MATLAB: Fill holes in binary Image

backgroundforegroundimage processingImage Processing Toolboximage segmentationmasksubtraction

Hey Guys,
I extracted the background by using the difference and now I want to work on my mask. The image below is currently mask of the binary image after filling it out with imfill(..'holes'). But unfortunately not everything of the body is filled out. Is there a way to fill out the middle part of the body? Thank you very much.

Best Answer

You could try imclose() followed by imfill()
se = strel('disk', 20, 0);
mask = imclose(mask, se);
mask = imfill(mask, 'holes');
imshow(mask);
or you could try an active contour, like the attached demo.
There are fancier ways if you want to make sure the outer boundary doesn't change, but it's more work and I don't have time for that now. See if one of the two methods I gave above works OK for you.