Ask Your Question
1

Remove small objects from binary image

asked 2017-09-25 07:39:01 -0600

ajit20 gravatar image

updated 2017-09-25 08:00:44 -0600

Hello All,

I have an input binary image but with lot of unwanted particles which I want to remove small objects based on the area of the particles. image description

I have developed the code in MATLAB which works fine using bwareaopen function. image description

i came across connectedComponentsWithStats function which can help me solve my purpose, here is the section of my code:

Mat labels, stats, centroids;
connectedComponentsWithStats(inputbinaryimage, labels, stats, centroids, 8, CV_32S);

Later I verified the area of particles using stats output array which successfully detects those particles. Now I'm stuck at how to use the STAT_AREA function to filter out unwanted particles. One more thing is that the input image will be changing(position of the particles wont be same for the next image) so I can't use compare function to filter out using labels.

Apart from connectedComponents are there any other functions which can perform the same operation much faster on the input binary image to get the desired output image.

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
1

answered 2017-09-25 20:53:54 -0600

Tetragramm gravatar image

You want the morphology operations. Much faster than connectedComponents.

edit flag offensive delete link more
0

answered 2017-09-26 11:39:01 -0600

daveg2 gravatar image

As @Tetragramm mentioned, morphology will be faster than connected components. If you use a morphological open (i.e. erosion followed by dilate), the size of the larger objects will be preserved whilst the noise will be removed.

However, this won't get of the object on the right. Does your bwareaopen get rid of this, or are you doing further processing to remove it?

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-09-25 07:39:01 -0600

Seen: 15,756 times

Last updated: Sep 26 '17