Posted by
HansMaulwurf on
Jun 24, 2014; 9:59am
URL: http://imagej.273.s1.nabble.com/Analyze-Particles-gives-different-results-with-script-manual-tp5008392.html
Hello,
this is my first post here and I hope you can help me.
I'm trying to analyze pictures of an agricultural field experiment. I want to find out which is the leaf cover index of my plants.
Therefore I open the picture to be analyzed in ImageJ and do the following steps:
Image> Adjust...> Color Threshold, then I turn the picture in B&W and adjust the HUE and Brightness scale so that all green pixels of the plants are black and pixels of other colors are white.
After that I go on with: Analyze> Analyze Partciles...> mark Clear results> Ok
Than I get my results. Important for me is the result of the %area.
I got more than 800 pictures so I don't wanna do this all manual. I got a script, which gets this work down in a batch, but it doesn't work right.
In the following example I got round about 82,6% for green pixel when I analyzed it manual and only 47% when I let the script do the work. I used the same values in the HUE, Saturation and Brightness scale.
I think the script runs not right. I don't know the guy who wrote the script, so I can not ask him where the bug is.
Can anybody of you look over it and tell me what is wrong with it?
The script inverts the pictures, so that green pixels are white and others are black. Could that be the mistake? And what do I have to change in the script that it does not invert the pictures?
Output ImageJ

Original

Here's the script
//run("Threshold...");
// Color Thresholder 1.44p
// Autogenerated macro, single images only!
min=newArray(3);
max=newArray(3);
filter=newArray(3);
a=getTitle();
run("HSB Stack");
run("Convert Stack to Images");run("RGB Color");
border=25;
w=getWidth+border*2; h=getHeight+border*2;
run("Canvas Size...", "width=w height=h position=Center zero");
selectWindow("Hue");
rename("0");
selectWindow("Saturation");
rename("1");
selectWindow("Brightness");
rename("2");
min[0]=56;
max[0]=255;
filter[0]="pass";
min[1]=0;
max[1]=255;
filter[1]="pass";
min[2]=41;
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("Analyze Particles...", "size=0-Infinity circularity=0.00-1.00 show=Nothing summarize");
macro "Close All Windows" {
while (nImages>0) {
selectImage(nImages);
close();
I run it with following steps:
Process> Batch> Macro...
I hope you understand what I mean and anybody can help me!
Thank you in advance!