Macro to increase contrast to max

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Macro to increase contrast to max

eloiselockyer
Hi, I'm working with the following macro to perform particle analysis on a set of double channel images:

dir=getDirectory("Choose a Directory");
print(dir);
greenDir=dir + "/Green/";
blueDir=dir + "/Blue/";
print(greenDir);
print(blueDir);
File.makeDirectory(greenDir);
File.makeDirectory(blueDir);
list = getFileList(dir);

for (i=0; i<list.length; i++) {
     if (endsWith(list[i], ".tif")){
               print(i + ": " + dir+list[i]);
             open(dir+list[i]);
             imgName=getTitle();
         baseNameEnd=indexOf(imgName, ".tif");
         baseName=substring(imgName, 0, baseNameEnd);

         run("Split Channels");
         roiManager("Reset");

         selectWindow("C1-" + imgName);  
         run("Duplicate...", "title=");
         saveAs("Tiff", greenDir + "originalgreen" + baseName);
         selectWindow("C1-" + imgName);
         setAutoThreshold("Default dark");
         //run("Threshold...");
         //setThreshold(1, 255);
         setOption("BlackBackground", false);
         run("Convert to Mask");
         run("Analyze Particles...", "size=60-Infinity pixel show=Outlines display exclude summarize add");
         selectWindow("originalgreen" + imgName);
         roiManager("Show All with labels");
         run("Flatten");
         saveAs("Tiff", greenDir + baseName + "overlaygreen.tif");
         close();
     }
}

Before performing particle analysis, I would like to include a line that sets the min and max to 0 in the adjust contrast window. I'm not sure how to write this as when I record this being done on one image the macro recorder line is run("Apply LUT"); which doesn't specify the min and max to be 0.
Reply | Threaded
Open this post in threaded view
|

Re: Macro to increase contrast to max

Michael Schmid
 > Before performing particle analysis, I would like to include a
 > line that sets the min and max to 0 in the adjust contrast window.


Hi Eloise,

seems you are looking for the
   setThreshold(0, 0);
command.
https://imagej.nih.gov/ij/developer/macro/functions.html#setThreshold

If you press "Set" in the Threshold panel and enter the values, the
Macro Recorder records it.


Michael
________________________________________________________________
On 21/05/2017 12:37, eloiselockyer wrote:

> Hi, I'm working with the following macro to perform particle analysis on a
> set of double channel images:
>
> dir=getDirectory("Choose a Directory");
> print(dir);
> greenDir=dir + "/Green/";
> blueDir=dir + "/Blue/";
> print(greenDir);
> print(blueDir);
> File.makeDirectory(greenDir);
> File.makeDirectory(blueDir);
> list = getFileList(dir);
>
> for (i=0; i<list.length; i++) {
>       if (endsWith(list[i], ".tif")){
>                 print(i + ": " + dir+list[i]);
>               open(dir+list[i]);
>               imgName=getTitle();
>           baseNameEnd=indexOf(imgName, ".tif");
>           baseName=substring(imgName, 0, baseNameEnd);
>
>           run("Split Channels");
> roiManager("Reset");
>
>           selectWindow("C1-" + imgName);
> run("Duplicate...", "title=");
> saveAs("Tiff", greenDir + "originalgreen" + baseName);
> selectWindow("C1-" + imgName);
> setAutoThreshold("Default dark");
> //run("Threshold...");
> //setThreshold(1, 255);
> setOption("BlackBackground", false);
> run("Convert to Mask");
> run("Analyze Particles...", "size=60-Infinity pixel show=Outlines display
> exclude summarize add");
> selectWindow("originalgreen" + imgName);
> roiManager("Show All with labels");
> run("Flatten");
> saveAs("Tiff", greenDir + baseName + "overlaygreen.tif");
>           close();
>       }
> }
>
> Before performing particle analysis, I would like to include a line that
> sets the min and max to 0 in the adjust contrast window. I'm not sure how to
> write this as when I record this being done on one image the macro recorder
> line is run("Apply LUT"); which doesn't specify the min and max to be 0.

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