# Best way to remove unwanted region from image

I am finding the techniques to remove unwanted regions (small dots) from image. I have an image that includes object and some unwanted region (small dots- see first image). I want to remove it. Hence, I use some morphological operator example 'close' to remove. But it is not perfect. Do you have other way to remove more clear (similar second image)? You can download example image at here  • can you try opening ; erosion (to remove unwanted areas) followed by dilation (to restore the wanted area to its original size). – keen marozva Jun 6 '17 at 18:30

Looks like you are using Matlab. Try bwareaopen(I, N), where I is the original binary image and N is the estimated size of each unwanted connected region.

You can try edit bwareaopen for more details. Basically the algorithm tries to find the size of connected regions. Connected-component labeling with union-find algorithm is expected to get you there.

• @lenon310: Thank you so mục .You ar right. But I want to refer one method (not function).Do you know which is method – John Mar 25 '14 at 13:47

Referring to MATLAB, the basic steps are

Determine the connected components:

CC = bwconncomp(BW, conn);

Compute the area of each component:

S = regionprops(CC, 'Area');

Remove small objects:

L = labelmatrix(CC); BW2 = ismember(L, find([S.Area] >= P));

At the last step, after obtaining $$L$$, you might as well retain the component with the largest area if you are interested in a single component. This would make the algorithm invariant to the size of the noise.

Easy problem. Use silhouette image label (bwlabel), region property (regionprops) and area open (bwareaopen) functions in MATLAB after defining the fraction of the blobs to remove as a function of the area of the largest blob, which is your object. The fragment of the code is as follows:

alpha=0.05;%fraction of insignificant blobs in an image

[labeledImage,nblobs]=bwlabel(Image);
if nblobs>1
Measures=regionprops(labeledImage,'Area');
Image=bwareaopen(Image,ceil(alpha*max([Measures.Area])));
end


You could try to apply anisotropic filtering as described by Perona and Malik (and many papers after that).

I would go in two steps: -first step low pass filter of your image, likely the unwanted region will be smoothed out, but the good region will be a bit blurred. -second step apply a diffusion a la perona and malik and use the first step to speed/slow diffusion depending you are in the good region (with data left) or a bad one (filtered out).

That is however if you are ok with obtaining a greyscale image, if you want to keep it binary it would not work I guess.

• I implement it but its result shows not good. – John Mar 25 '14 at 13:47