Removing blobs from a binary image

前端 未结 2 1908
感情败类
感情败类 2021-02-14 19:10

I have a binary image which contain few blobs.

I want to remove blobs which are less than a certain area.

Can any one suggest me a way?

I am using Open-C

2条回答
  •  暖寄归人
    2021-02-14 19:41

                //src_gray is your image that we threshold
                threshold(src_gray, threshold_output, NULL, 255, THRESH_OTSU);
                /// Find contours
                findContours(threshold_output, contours, hierarchy, RETR_TREE, CHAIN_APPROX_SIMPLE, Point(0, 0));
                /// Approximate contours
                vector boundRect(contours.size());
                for (unsigned int i = 0; i < contours.size(); i++)
                {   //identify bounding box
                    boundRect[i] = boundingRect(contours[i]);
                }
                for (unsigned int i = 0; i < contours.size(); i++)
                {
    
                    if ((boundRect[i].area() < //enter your area here))
                    {
                        src_gray(boundRect[i])=//set it to whatever value you want;
                    }
                }
    

    Well give this a try...

提交回复
热议问题