我有一个包含少量 Blob 的二进制图像。

我要删除小于特定区域的 Blob 。

有人可以建议我吗?

我正在使用Open-CV。我做了扩张和侵 eclipse 以获得这些 Blob 。因此,我需要一些其他方法来去除小于特定区域的铰孔。

最佳答案

您可以执行以下操作:

// your input binary image
// assuming that blob pixels have positive values, zero otherwise
Mat binary_image;

// threashold specifying minimum area of a blob
double threshold = 100;

vector<vector<Point>> contours;
vector<Vec4i> hierarchy;
vector<int> small_blobs;
double contour_area;
Mat temp_image;

// find all contours in the binary image
binary_image.copyTo(temp_image);
findContours(temp_image, contours, hierarchy, CV_RETR_CCOMP,
                                                  CV_CHAIN_APPROX_SIMPLE);

// Find indices of contours whose area is less than `threshold`
if ( !contours_all.empty()) {
    for (size_t i=0; i<contours.size(); ++i) {
        contour_area = contourArea(contours_all[i]) ;
        if ( contour_area < threshold)
            small_blobs.push_back(i);
    }
}

// fill-in all small contours with zeros
for (size_t i=0; i < small_blobs.size(); ++i) {
    drawContours(binary_image, contours, small_blobs[i], cv::Scalar(0),
                                                 CV_FILLED, 8);
}

10-08 16:26