Irregular bubble area calculation

plugin
segmentation
macro
imagej
Tags: #<Tag:0x00007fb87bdd6900> #<Tag:0x00007fb87bdd67c0> #<Tag:0x00007fb87bdd6658> #<Tag:0x00007fb87bdd64f0>

#1

Hi.

I’m trying to calculate the area of the bubbles present in an image. The first image is the one I am currently using.

By applying the following Maco, I am getting the results obtained in the second image.

setThreshold(0, 254);
run("Create Mask");
run("Analyze Particles...", "exclude clear add");
close();
resetThreshold();
roiManager("Show All");

You can see that not all the bubbles are captured, especially those that are very long (having a large area).

Any suggestions to solve this problem? Thanks.


Something that I want to do but I couldn’t figure out how to do it is:

  • fill the bubbles in white color.
  • leave the background in black.
  • use Shape Descriptor Maps to get the distribution.

#2

Hey @MoeAmine

So… your image is a tricky one. First - if you zoom in on the ROIs the Particle Analyzer is grabbing, you’ll see they are being outlined. As opposed to selecting the bubbles themselves, the outline of the bubbles is being selected as ‘object’. Too - the bubbles don’t quite all ‘close’ … which is why you are only getting some.

I would lean towards another route in this case… perhaps something like:

run("Gaussian Blur...", "sigma=2");
setAutoThreshold("Default dark");
//run("Threshold...");
setAutoThreshold("Huang dark");
run("Create Mask");

setOption("BlackBackground", true);
run("Skeletonize");

That gives you something that looks like this:

You could try to close some of the gaps working on the binary image (after the create mask call) - just calling erode and dilate a few times… but knowing that certain combinations won’t work for everyone. That’s why I went with Huang as a threshold - seemed to be a bit more ‘robust’.

And then using MorpholibJ’s segmentation tool: Morphological Segmentation to label your bubbles. Again - because some bubbles don’t close… you won’t select them all.

My quick test looks like this:

Perhaps someone else here has some insight in this? I am sure there are more refined tools and workflows you can use. @biovoxxel or @iarganda - any thoughts on this one?

But at least this gives you a start…

eta


#3

Hi @MoeAmine,

could you also post the original image (best as a .png image to avoid jpg-artifacts). Potentially, starting with a different pre-processing will help in better delineate the bubbles. Since you will need to exclude the ones touching the borders, a separation should happen before that, to avoid loosing so maly which are connected to image border touching bubbles.


#4

Hi @etarena

Thanks for your input. Very interesting! I have done several trials and I could get some better results. I am also considering the use of “Close-” which works until a certain point until it starts giving some straight lines.


#5

Hello @biovoxxel

The original image is relatively large and only this portion is what I am interested in. I have posted the image in the format of PNG.

True, the bubbles touching the borders should be exluded too since they are not representative as they are parts of some bubbles are not shown in the image.

The way I obtained this is that I took the difference between two images:



#6

I think your image is quite complicated to get a result of what is the background and what is the foreground.
Can you change the illumination somehow so you know what is inside and what is outside a bubble?


#7

You might want to enhance and close the edges of the bubbles first by using MorphoLibJ’s directional filtering. For instance:
35 PM

And then apply the Morphological Segmentation plugin: