Erase small pixels - Analyze particles?

I feel like the answer is right there for me to grasp it, but I can’t.
I would like to erase small pixels in an binary image. Like, everything composed of fewer than e.g. 4 pixels must go (form does not matter too much).
I am analyzing trabeculae and trabecula can not be so small, ergo those small pixels must go to do a correct analysis.
I know I am already using the median filter, but it also erases pixels at the borders of the trabecula (since if there are more black pixels than white, the median will be black).
I know with analyze particles you can select such small bodies, but I do not really know how to do something with them, I just can mark them individually.
My goal is to be able to do this in a macro for many many images.
Thank you very much.

PS: I have posed another question here, but I got no answers. Maybe you can help?

you’re right. You can use analyze particles to do this.
If you use analyze particles to detect the objects you measure, you can just set the min. Size to 5, so smaller particles will not be included in the result.

You can also use analyze particles to eliminate the small objects from the mask. Set the min. size to 5. Then choose Masks for the Show option and select In situ Show if you want to work on the input-mask, instead of creating a copy.

In a macro it reads like this:

run("Analyze Particles...", "size=5-Infinity show=Masks in_situ");

Best regards,

1 Like

Thank you so much!
This is perfect.
Vielen lieben Dank :smiley:


just an add-on since Analyze particles is definitely a solution.

You can use the MorpholibJ library for these kind of operations and many more. You just need to follow the IJPB-plugins update site. Then “Size opening” (Plugins > MorpholibJ > Binary Images > Size Opening 2D/3D) allows you to set a minimum pixel (or voxel) size.

1 Like

I will also try it out, thank you very much :smiley: