Login  Register

Re: Batch Conversion to 8-but grayscale

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options Options
Embed post
Permalink
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: Batch Conversion to 8-but grayscale

Christine Labno-2
38 posts
Hi Hannah,

Here is some code from our website that will convert 16-bit grayscale images to 8-bit grayscale images.  If you don't want to overwrite the original files, erase the // from in front of the five lines before and one line after the run 8-bit command.

Best,
Christine


-------------begin code--------------
// This macro opens a directory of tiff images and resaves each
//      as 8-bit
// Univ of Chicago, Vytas Bindokas, Jul'06  requires("1.35l");

    dir = getDirectory("Choose a Directory ");
    list = getFileList(dir);
print(list.length);

 setBatchMode(true);               // runs up to 6 times faster
    for (f=0; f<list.length; f++) { //main files loop
        path = dir+list[f];
 print(path);
        showProgress(f, list.length);
        if (!endsWith(path,"/")) open(path);
if (nImages>=1) {
  if (endsWith(path,"f")) { //do only tif files

   start = getTime();
//   t=getTitle();
//   s=lastIndexOf(t, '.');
//   t=substring(t, 0,s);
//   t=replace(t," ","_");
 //  t2= t +'B16.tif';
run("8-bit");
//   rename(t2);
   saveAs("tif", path);
   run("Close");
       }
  }
}
 print((getTime()-start)/1000);

--------------end code--------------------
--------------------------------------------
Christine Labno, Ph.D.
Asst. Technical Director
Light Microscopy Core
University of Chicago
Office of Shared Research Facilities
KCBD 1250 900 E. 57th St.
(773) 834-9040 (phone)

________________________________________
From: ImageJ Interest Group [[hidden email]] on behalf of Hannah S [[hidden email]]
Sent: Saturday, August 17, 2013 8:52 PM
To: [hidden email]
Subject: Batch Conversion to 8-but grayscale

I am trying to convert a folder of JPG files to 8-bit grayscale images. I
have followed these instructions, but only seem to get 8-bit color, not
grayscale images.

I currently am saving the text file from this link
http://rsb.info.nih.gov/ij/macros/ListFilesRecursively.txt asthat
"directory_call.txt" in  "imageJ/macros/" folder. The I run the macro,
"Menu/plugins/macro/run", select the directory, then i run the batch
converter plugin.

How can I modify this to convert to 8-bit grayscale?



--
View this message in context: http://imagej.1557.x6.nabble.com/Batch-Conversion-to-8-but-grayscale-tp5004471.html
Sent from the ImageJ mailing list archive at Nabble.com.

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html