Login  Register

Re: How to limit to threshold for measurement in a macro

Posted by Andrew Sanchez on Jul 22, 2015; 11:13pm
URL: http://imagej.273.s1.nabble.com/How-to-limit-to-threshold-for-measurement-in-a-macro-tp5013681p5013707.html

This might (hopefully) help you.  It's the macro I use to get measurements via Analyze Particles from a thresholded image, based on a previously selected area.  It was auto generated using Record Macro.

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]=36;
max[0]=128;
filter[0]="pass";
min[1]=34;
max[1]=210;
filter[1]="pass";
min[2]=30;
max[2]=225;
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);
// Color Thresholding-------------

// counts number of green pixels under total area column in the summary table.  excludes pixel groups of less than 10 pixels
run("Analyze Particles...", "size=10-Infinity summarize");