在位图中查找blob

goo*_*dev 6 c# vb.net graphics graph graph-algorithm

我使用AForge.Net在位图中查找blob,我的位图如下:

在AForge.Net中搜索blob

我的问题是AForge.Net只检测到一个blob,实际上细线上有两个连接的blob.

我的问题是有一个算法可以确定它们之间有两个连接很薄的大blob?我如何在C#或VB中实现此算法?

样品图片:

样品图片

Sim*_*ier 7

正如其他人所建议的,我会使用OpenCv而不是AForge(似乎AForge已经有一段时间没有更新,OpenCv有很多可用的样本).使用C#,我建议使用OpenCvSharp nuget包.它很容易使用,因为代码看起来像C++或python代码,就像大多数样本一样.

所以,OpenCv有一个blob探测器,但是它会检测blob中心,所以在你的情况下,你看起来比轮廓更多(通常是这种情况).

幸运的是,使用OpenCv和你的样本图像,它只是没有做任何花哨的事情(我们甚至不必先侵蚀图像),我们可以使用findContours,过滤一些毛刺,并获得convexHull.这是一个示例代码,演示了:

using (var src = new Mat(filePath))
using (var gray = new Mat())
{
    using (var bw = src.CvtColor(ColorConversionCodes.BGR2GRAY)) // convert to grayscale
    {
        // invert b&w (specific to your white on black image)
        Cv2.BitwiseNot(bw, gray);
    }

    // find all contours
    var contours = gray.FindContoursAsArray(RetrievalModes.List, ContourApproximationModes.ApproxSimple);
    using (var dst = src.Clone())
    {
        foreach (var contour in contours)
        {
            // filter small contours by their area
            var area = Cv2.ContourArea(contour);
            if (area < 15 * 15) // a rect of 15x15, or whatever you see fit
                continue;

            // also filter the whole image contour (by 1% close to the real area), there may be smarter ways...
            if (Math.Abs((area - (src.Width * src.Height)) / area) < 0.01f)
                continue;

            var hull = Cv2.ConvexHull(contour);
            Cv2.Polylines(dst, new[] { hull }, true, Scalar.Red, 2);
        }

        using (new Window("src image", src))
        using (new Window("dst image", dst))
        {
            Cv2.WaitKey();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述