How to obtain automatically image with selection after color threshold?

Dear ImageJ users,

I am using Fiji to process my images. My goal is to extract root surface area from the background (please see Figure 1 for the original image) using “Color threshold”, followed by “Select” (please see Figure 2), then I type on “M” to export the measurement.
Figure1.tif (9.1 MB)

Figure2.tif (1.6 MB)

505_R2B1.tif (9.1 MB)

I have used Macro Recorder to create my macro in order to process images in batch (please see my macro below). However, the outcome that I got was like Figure 3 (Black-and-white for red, green, blue channel each), while the outcome that I expected are images like Figure 2 because I need to remove noise manually. In other words, color threshold was successfully applied but the selection was not done.

run("Color Threshold...");

// Color Thresholder 2.0.0-rc-69/1.52p
// Autogenerated macro, single images only!
min=newArray(3);
max=newArray(3);
filter=newArray(3);
a=getTitle();
run("RGB Stack");
run("Convert Stack to Images");
selectWindow("Red");
rename("0");
selectWindow("Green");
rename("1");
selectWindow("Blue");
rename("2");
min[0]=135;
max[0]=255;
filter[0]="pass";
min[1]=114;
max[1]=255;
filter[1]="pass";
min[2]=120;
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 Result of 0");

I have looked for solutions in the forum but I haven’t found one which can fit my situation. Can anyone help me to solve this problem? Thank you very much.

Use your final image (“Result of Result of 0”) as a 0/1-mask and apply it onto your original image.

In practice:
Convert your final image into a 0/1-mask by

// eventually: run("Invert", "stack");
run("Divide...", "value=255 stack");

The resulting image has (to have) a black background (=0) and object area (=1).

Multiply the channels of your original image with the channels of this 0/1-mask

imageCalculator("Multiply create stack", "Untitled","Untitled-1");

(Use the correct image title instead of “Untitled”.)

Is this what you want?

Thank you phaub for providing a solution. Sorry for my late reply because I run into some problem and I’ve been trying to figure it out…

I have followed your suggestion to modify the code into:

selectWindow(“Result of Result of 0”);
run(“Invert”, “stack”);
run(“Divide…”, “value=255 stack”);
imageCalculator(“Multiply create stack”, “Result of 0”,“Result of Result of 0”)

What I got was indeed two images: black background and object area (please see Figure 4), which is not what I expected to have (Figure 2 of my 1st post). And there is no measurement of the object area.

Figure4.tif (286.3 KB)

Would you have any other idea to solve this problem?

Thank you!

In

there are the two images “Result of 0” and “Result of Result of 0”.

But what is the result of

??

Make sure that “Result of Result of 0” contains the correct mask.
Check by adjusting Brightness/Contrast.

One more hint: Learn to rename images in your macro to make your code more readable and safe.