IJ Color Thresholding in Macro
Posted by Steve R on Dec 02, 2014; 11:21pm
URL: http://imagej.273.s1.nabble.com/IJ-Color-Thresholding-in-Macro-tp5010727.html
when recording a Macro, I do a Color Threshold, and hit the Macro button to send the threshold settings into the macro, it also adds a bunch of routines that I don't want, like HSB Stack & some other stuff that ends up making the resultant image completely white except for the thresholded voids. This makes it hard to see if it picked the void area correctly without seeing the image in the background. If I Color Threshold manually & then manually do a analyze Particles, I can pick Outline Overlay as an option & get what I want.
Is there not a way to record in the Macro just the Color Threshold Settings as if I were doing it manually?
See the Macro below, issue is in the Color Thresholder 1.48v section
Thanks, Steve
run("Enhance Contrast...", "saturated=0.3 equalize");
// Color Thresholder 1.48v
// Autogenerated macro, single images only!
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]=16;
max[0]=250;
filter[0]="stop";
min[1]=101;
max[1]=173;
filter[1]="pass";
min[2]=127;
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);
// Colour Thresholding-------------
run("Set Scale...", "distance=599.24 known=1 pixel=1 unit=INCH global");
//Example macro calculating stats from a results table column
//Import any data into a results table and then use the following to extract summary stats
//The examples use "Area" as the column heading
//All results checked with OpenOffice Calc, note: variance uses n-1 to correct for sample bias
//Some variables
N=0;
total_area=0;
mean_area=0;
total_variance=0;
variance_area=0;
SD_Area=0;
SE_Area=0;
CI95_Area=0;
max_area=0;
min_area=0;
Voiding_Total_Area=0;
Percent_Voiding=0;
//Generate a results table
run("Clear Results");
run("Set Measurements...", "area redirect=None decimal=4");
run("Analyze Particles...", "size=0.00010-Infinity show=[Overlay Outlines] display clear include summarize in_situ");
//Number of results in "Area" Column
N = nResults;
//Mean "Area"column
for (a=0; a<nResults(); a++) {
total_area=total_area+getResult("Area",a);
mean_area=total_area/nResults;
}
//Voiding Total_Area;
//for (a=0; a<nResults(); a++) {
//total_area=total_area+getResult("Area",a);
//Voiding_Total_Area=total_area/2;
Voiding_Total_Area=total_area;
//%_Voiding;
for (a=0; a<nResults(); a++) {
total_area=total_area+getResult("Area",a);
Percent_Voiding=total_area/12.08*100/2;
}
//Max value in "Area" column
for (a=0; a<nResults(); a++) {
if (getResult("Area",a)>max_area)
{
max_area = getResult("Area",a);
}
else{};
}
//Min value in "Area" column (note: requires max value)
min_area=max_area;
for (a=0; a<nResults(); a++) {
if (getResult("Area",a)<min_area)
{
min_area = getResult("Area",a);
}
else{};
}
//Variance of "Area" column
for (a=0; a<nResults(); a++) {
total_variance=total_variance+(getResult("Area",a)-(mean_area))*(getResult("Area",a)-(mean_area));
variance_area=total_variance/(nResults-1);
}
//SD of "Area" column (note: requires variance)
SD_Area=sqrt(variance_area);
//SE of "Area" column (note: requires SD)
SE_Area = (SD_Area/(sqrt(N)));
//95% CI of column "Area" (note: requires SE)
CI95_Area = 1.96*SE_Area;
//Return values
print("N = "+N);
print("Mean = "+mean_area);
print("Var = "+variance_area);
print("SD = "+SD_Area);
print("SE = "+SE_Area);
print("95% CI = "+CI95_Area);
print("Max = "+max_area);
print("Min = "+min_area);
print("Voiding Total Area = "+Voiding_Total_Area);
print("Percent_Voiding = "+Percent_Voiding);
//Richard