How to include holes within the segmentized regions for calculating total area

I have image that looks like this:

And with this code:

open("/Users/pdubois/myimage1.tif");
run("8-bit");
run("Set Scale...", "distance=96 known=1 pixel=1 unit=um global");
run("Despeckle");
setAutoThreshold("Mean dark");
run("Set Measurements...", "area redirect=None decimal=3");
run("Analyze Particles...", "  show=Outlines display exclude clear include summarize add");

I can segmentized into the following images:

As stated there how could I include the areas enclosed for calculating to total area size?

There hundreds of image like this, I need to do. So I can’t manually select area with drawing line.

Hi @Peverall_Dubois

To replicate the following, you first need to apply the threshold to your image with

run("Convert to Mask");

Then you can use morphological filtering to ‘Close’ the nearby areas. If you use the base imageJ filters Process>Binary>Options you can use the following

run("Options...", "iterations=5 count=2 black do=Close");

I got the following result (Note that your tif image was corrupted so I had to filter it, thus the final result might look a little different for you on your original data.

Otherwise if you want fancier implementations, you can use MorphoLibJ plugins.

run("Morphological Filters", "operation=Closing element=Disk radius=5");

Gives

Best

2 Likes

Based on your code, he black area enclosed in the white is not included as total area.
How can I include it?

Can you give the complete code?

I tried with this code:

open("/Users/pdubois/myimage1.tif");
run("8-bit");
run("Set Scale...", "distance=96 known=1 pixel=1 unit=um global");
run("Despeckle");
run("Morphological Filters", "operation=Closing element=Disk radius=5");
setAutoThreshold("Minimum dark");
setThreshold(157, 255);
run("Analyze Particles...", "display clear summarize add");

And get this:

I’n not sure if the area of size 0.791 is based on all red region or all region enclosed by the yellow line (grey area within included).

P.D.

Indeed that value is with the hole still being excluded.

Under “Analyze Particles”, ensure that “Include Holes” Is checked

1 exclude holes.tif 0.768 255 0.062 0.062 1.062 1.302 1
2 include holes.tif 0.910 215.304 0.062 0.062 1.062 1.302 1

This will work as long as this is an actual hole. By that I mean that if the excluded area is still connected to the rest of the image, like in your first example, then it will always exclude it, regardless of the Include Holes setting