Inconsistent area % calculation

Dear Forum,

I am a relatively new user of imagej and have the following issue:

I’d like to use color thresholding to calculate the % area of green leaves compared to the background.

My process is:
Adjust → Color threshold
Hue: 39, 109 (Pass unchecked)
Sat: 0, 255 (Pass checked)
Brightness: 0, 255 (Pass checked)
Default, Red, HSB, Dark Background checked

Image type → 8-bit color
Analyze → Measure (with area % selected)

With “Bi 1D”, this process gives 38% which is real. With “Bi 2F” and other images of this same batch, it gives 100%. Can someone please figure out how to fix this?

Thank you so much in advance.

Do not convert the result to 8bit colour (palette image), but to 8bit greyscale. Also the analyze command expects a threshold (of the now binary image) to be set.

Best thing is to record a macro and post it here so people can see exactly what you are doing.
The colour thresholding can also be recorded (by pressing the macro button in the dialogue).

1 Like

Hi Gabriel,

Thanks for your response. I’d like to use color thresholding as its difficult to differentiate the green leaves from other things using greyscale.

Here are the macros and their respective results:

AreaCalcBi1D.ijm (103 Bytes)

      Area                Mean      Min  Max  %Area

1 24064000 44.797 0 255 38.082

AreaCalcBi2F.ijm (105 Bytes)

      Area                Mean      Min  Max  %Area

1 24064000 55.243 0 255 100.000

Why does one give the correct %Area and the other not?

Hi, As I said, you need to record the colour thresholder with the “macro” button (at the moment your macro launches the dialog, but does nothing). Do NOT convert the RGB image to 8bit colour, you need to threshold the RGB image and then process the 8bit GREY result as in this macro.

// Color Thresholder 1.53j
// 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]=40;
max[0]=110;
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);
// Colour Thresholding-------------
//binary closing to remove noise (or something like this)
run("Minimum...", "radius=4");
run("Maximum...", "radius=4");

Obviously you will need to change above the Hue Saturation and Brightness to whatever values segment your green objects. This is just an example.

Thanks! Got it to work reliably now by color thresholding, switching to 8-bit greyscale, and then thresholding again.