MATLAB: How to fill holes having area less than some maximum threshold value

image analysisimage processingImage Processing Toolboximage segmentation

I have a binary image, I want to fill only those holes having area less than say 20, and holes having area more than that remains unfilled…how can I do this…any sort of help is appreciated

Best Answer

Invert the image so that the holes are now foreground blobs, then call bwareaopen, and invert again
binaryImage = ~bwareaopen(~binaryImage, 20);