Posted by
danih on
Oct 17, 2012; 12:00am
URL: http://imagej.273.s1.nabble.com/Threshold-Colour-select-macro-question-tp5000412p5000423.html
Dear Michael and Gabriel,
Thank you so very much! You were absolutely right!! I had to duplicate the original, create a selection based on the color threshold (after converting it to 8bit) , then restore the selection in the original, then delete. My batch is running perfectly now. Thanks again!!
The new/improved code is pasted below:
imgName=getTitle();
run("Duplicate...", "title=1.tif");
run("Threshold Colour");
// Threshold Colour v1.12a------
// Autogenerated macro, single images only!
// G. Landini 27/Sep/2010.
//
min=newArray(3);
max=newArray(3);
filter=newArray(3);
a=getTitle();
run("HSB Stack");
run("Convert Stack to Images");
selectWindow("Hue");
rename("0");
selectWindow("Saturation");
rename("1");
selectWindow("Brightness");
rename("2");
min[0]=0;
max[0]=207;
filter[0]="pass";
min[1]=0;
max[1]=255;
filter[1]="pass";
min[2]=0;
max[2]=255;
filter[2]="pass";
for (i=0;i<3;i++){
selectWindow(""+i);
setThreshold(min[i], max[i]);
run("Convert to Mask");
if (filter[i]=="stop") run("Invert");
}
imageCalculator("AND create", "0","1");
imageCalculator("AND create", "Result of 0","2");
for (i=0;i<3;i++){
selectWindow(""+i);
close();
}
selectWindow("Result of 0");
close();
selectWindow("Result of Result of 0");
rename(a);
// Threshold Colour ------------
run("8-bit");
run("Create Selection");
selectWindow(imgName);
run("Restore Selection");
run("Clear", "slice");
--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html