Fill holes touching edge

In the attached image (a mask as a result of previous steps) there are holes in the bottom and to the right touching the edge of the window. The next macro steps do not remove these holes, but I wish to do so. How do I accomplish that?

	run("Select All");
	run("Fill Holes");
	run("Invert");
	run("Fill Holes");
	run("Invert");

Solution using the Particle Analyzer:

Invert the mask such that the holes are objects (value 255).
Use the particle Analyzer with the exclude on edges option turned on.
Then output as new mask using Show: Masks

Although I lose the lefthand vertical bar too, particle analysis may be a building block. Especially as I can limit to larger, not large, particles. Thanks for the shortcut.

Fill_Border_Holes.txt macro in the Morphology collection does that:

Fill_Border_Holes.txt Fills holes including those touching the borders of the image This cannot be done with the “Fill Holes” command alone. Holes are assumed to be not only the traditional 4-connected background elements, but also those that touch the image borders, but extending no more than 2 contiguous borders (i.e. touching one border or a corner).

https://blog.bham.ac.uk/intellimic/g-landini-software/

1 Like