【问题标题】:Fastest method to find the greatest length across a blob找到blob最大长度的最快方法
【发布时间】:2014-06-14 01:53:43
【问题描述】:

使用 BlobCounterBase.GetObjectInformation,我可以从图像中检索 blob。找到整个 blob 的最大长度的最快方法是什么?它不仅仅是 blob 矩形的斜边。

我可以提取所有边缘点(使用 GetBlobsEdgePoints 方法),计算每对边缘点之间的长度并找到最大长度。但是这种方法很慢,尤其是当我处理可能有数千个 blob 的图像时。

【问题讨论】:

  • 也许look at this technique 可以替代?
  • 谢谢,罗杰。 Convex Hull 的想法让我想起了 Aforge 有一个 GrahamConvexHull 类。使用它,我能够显着减少我必须比较的点数,才能找到整个 blob 的最大距离。

标签: image-processing aforge


【解决方案1】:

这是一个对我的应用程序运行速度非常快的解决方案(再次感谢 Roger Rowland 提出的解决方案):

    private double GetGreatestLength(Blob blob)
    {
        try
        {
            GrahamConvexHull hullFinder = new GrahamConvexHull();

            var hullPoints = hullFinder.FindHull(_blobCounter.GetBlobsEdgePoints(blob));
            var maxPoints = GetMaxPoints(hullPoints);

            return maxPoints.distance * _micronsPerPixel;
        }
        catch (Exception)
        {
            return 0;
        }
    }

    struct MaxPoints
    {
        public IntPoint firstPoint;
        public IntPoint secondPoint;
        public double distance;

        public MaxPoints(IntPoint first, IntPoint second, double dist)
        {
            this.firstPoint = first;
            this.secondPoint = second;
            this.distance = dist;
        }
    }

    private MaxPoints GetMaxPoints(IEnumerable<IntPoint> points)
    {
        var data = from a in points
                   from b in points
                   select new MaxPoints(a, b, GetDistance(a, b));

        double maxDistance = data.Max(d => d.distance);

        return data.First(d => d.distance == maxDistance);
    }

    private double GetDistance(IntPoint a, IntPoint b)
    {
        return Math.Sqrt(Math.Pow((a.X - b.X), 2) + Math.Pow((a.Y - b.Y), 2));
    }

【讨论】:

    猜你喜欢
    • 2013-11-20
    • 2010-09-30
    • 2021-11-27
    • 1970-01-01
    • 2017-08-29
    • 1970-01-01
    • 2021-10-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多