MATLAB: Removing regions with holes

euler numberholesimage analysisImage Processing Toolbox

I have a mask image with the white regions being the region of interest. Now I want to remove all the white regions that have black hole(s) inside and retain only the solid white shapes (mostly observed along the column boundaries). The mask image is attached. Any help will be greatly appreciated.

Best Answer

BW = bwpropfilt(yourmask, 'Solidity', [0.94, 1]);
you can change the value of 0.94 depending on how strict you want to be, if you set it to 1 be very strict