Login  Register

Macro to increase contrast to max

Posted by eloiselockyer on May 21, 2017; 10:37am
URL: http://imagej.273.s1.nabble.com/Macro-to-increase-contrast-to-max-tp5018770.html

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.