Create ROI from color threshold to lift object from background [batchable]?

Hello all, I am quantifying the area of mildew lesions on the surfaces of leaves on a batch of images. I can nearly isolate the mildew colonies by exploiting the a* channel in LAB color space. The issue is, that while the colonies separate from the green leaf tissue in LAB, they are nearly the same ‘color’ as the platform on which the image was shot, making it impossible to separate from the background. Trying to simply target the colonies via standard color thresholding is unstable, due to variance between images. However, LAB has proven robust separation of the mildew colonies across the whole image sequence. I can however separate the entire leaf (green leaf + mildew infested portion) from the background, to create a nearly perfect outline of the leaf.

Thus, I would ideally be able to first outline the entire leaf area and “lift” it from the background, and then convert the remaining leaf image to LAB to threshold out the mildew colonies for quantification.

While I can do this manually on an image-by-image basis quite successfully with color threshold > select, I can’t automate this because the color threshold macro automatically produces the binary. Given my processing pipeline, my process must be automated.

In short, I’m looking to add a pre-processing step to “delete” all pixels that are NOT within a certain HSB range, and THEN continue segmenting/thresholding the remaining pixels.

Is this possible? Thank you greatly in advance.

Sample input image

Image converted to LAB. Note the lesions withing the leaf surface. Clearly visible, but have the same value as background.

What I would like to do: delete all the red in this threshold first, and then convert the remaining to LAB and continue thresholding, to avoid confusing the lesions with background:

1 Like

How about inverting the threshold and analysing particles with ROIs stored in the ROI Manager, then selecting every ROI to lift a leaf? With the copy of your first sample input image above on the sytem clipboard, run this macro:

run("Duplicate...", "title=LAB");
run("Lab Stack");
setAutoThreshold("Default dark");
run("Analyze Particles...", "size=100-Infinity exclude show=Nothing add slice");
roiManager("Select", 0);
run("Duplicate...", "title=[Lifted 1]");

You can detect/threshold the profiles of the leaves as binary objects, then go back to the original and detect/threshold the diseased regions (regardless of whether it is the same intensity as the background). Then apply a logical AND between those two image. The result should be the diseased regions within the leaves.
Is that what you are after?


Can this be okay?mildiou

1 Like

In fact, this is exactly what I’m after. Did you use one a method similar to the two suggestions above, or some other technique?


1 Like

Thanks, I just tried this. Works very well! Simple case of me overthinking…I think this will be well suited to my process. Thanks to all

1 Like


run("Duplicate...", "title=1");
run("Duplicate...", "title=2");
run("Lab Stack");
run("Split Channels");
setAutoThreshold("Default dark");
setOption("BlackBackground", true);
run("Convert to Mask");
run("Set Measurements...", "area mean add redirect=None decimal=0");
run("Analyze Particles...", "size=100-Infinity display exclude include add");
roiManager("Select", newArray(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22));
roiManager("Select", 0);
run("Restore Selection");
run("Clear Outside");
run("Select None");
1 Like

I have error to run, with the line:
roiManager(“Select”, newArray(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22));
It’s correct the text?

Hi @EdTerr5
The macro works well with the image posted on this post.
You could delete the line (“Select”, newArray (0,1,2 …
with the following code:

roiManager("select", a)

Test line by line with this image.