Removing blobs from a binary image

前端 未结 2 557
悲&欢浪女
悲&欢浪女 2021-02-14 19:18

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:35

                //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...

提交回复
热议问题