Which method to remove small unwanted region and fill holes I have a hard problem that need your help. I have a binary image that maintains some unwanted region (small white dot) and hole regions (in figure 1).My idea is that the first I will remove unwanted region by calculating area these region and then filter with small area value.At the second step, I fill in hole region to make clear image.What do you think best method to fill in hole region. D.Because my idea need threshold value to remove unwanted region. I want to find automatic method to do it. Do you have any idea to resolve it? Thank you so much. This is my reference code for remove unwanted region. But it need threshold term. You can download image test at here

function exImage=rmUnwantedRegion(Img,threshold)
    lb = bwlabel(Img);
    st = regionprops(lb, 'Area', 'PixelIdxList' );
    toRemove = [st.Area] &lt;threshold; % fix your threshold here
    exImage = Img;
    exImage( vertcat(st(toRemove).PixelIdxList ) ) = 0; % remove
 end
This code work fine for me. You try

RGB = imread('Image/input.png');

GRAY = rgb2gray(RGB);
threshold = graythresh(GRAY);
originalImage = im2bw(GRAY, threshold);

originalImage = bwareaopen(originalImage,250);
se = strel('disk', 10); %# structuring element
closeBW = imclose(originalImage,se);

imshow(closeBW);