霍夫变换问题

发布于 2024-08-04 22:10:11 字数 2434 浏览 3 评论 0原文

我以这种方式在 C# 中实现了霍夫变换:

        List<Point> forme = new List<Point>();

        forme.Add(new Point(260, 307));
        forme.Add(new Point(268, 302));
        forme.Add(new Point(273, 299));
        forme.Add(new Point(279, 295));
        forme.Add(new Point(285, 292));
        forme.Add(new Point(291, 288));
        forme.Add(new Point(298, 283));
        forme.Add(new Point(305, 280));
        forme.Add(new Point(312, 277));
        forme.Add(new Point(319, 274));
        forme.Add(new Point(325, 271));
        forme.Add(new Point(333, 268));
        forme.Add(new Point(340, 264));
        forme.Add(new Point(350, 259));
        forme.Add(new Point(356, 256));

            int width =  Math.Abs(forme[0].X - forme[forme.Count - 1].X);
            int height =  Math.Abs(forme[0].Y - forme[forme.Count - 1].Y);

            int halfWidth = width / 2; int halfHeigh = height / 2;

            double pmax = Math.Sqrt((width * width) + (height * height));
            double tmax = Math.PI * 2;

            // step sizes
            double dp = pmax / (double)width;
            double dt = tmax / (double)height;

            int[,] A = new int[width , height]; // accumulator array

            foreach (Point p in forme)
            { 

               for (int Theta = 1; Theta < height; Theta++)
                        {
                            double radius = ((double)(p.X) * Math.Cos(dt * (double)Theta)) + ((double)(p.Y) * Math.Sin(dt * (double)Theta)) ;

                            int k = (int)((radius / pmax) * width);
                            if (k >= 0 && k < width) A[k, Theta]++;
                        }

            }
            int goodTheta = 0;
            int goodRadius = 0;

            // maxMapIntensity c'est l'intensité maximale
            int maxMapIntensity = 0;
            for (int radius = 0; radius < width; radius++)
            {
                for (int theta = 0; theta < height; theta++)
                {
                    if (A[radius, theta] > maxMapIntensity)
                    {
                        maxMapIntensity = A[radius, theta];
                        goodRadius = radius;
                        goodTheta = theta;
                    }
                 }
            }

因此,根据我的理解,我现在已经找到了所有曲线交点的 theta 和半径。那我怎样才能找到真正的线呢?

有人声称我需要找到斜率和点,但我现在真的不清楚该怎么做。

感谢您的帮助,乔纳森

I implemented Hough Transform in C# this way:

        List<Point> forme = new List<Point>();

        forme.Add(new Point(260, 307));
        forme.Add(new Point(268, 302));
        forme.Add(new Point(273, 299));
        forme.Add(new Point(279, 295));
        forme.Add(new Point(285, 292));
        forme.Add(new Point(291, 288));
        forme.Add(new Point(298, 283));
        forme.Add(new Point(305, 280));
        forme.Add(new Point(312, 277));
        forme.Add(new Point(319, 274));
        forme.Add(new Point(325, 271));
        forme.Add(new Point(333, 268));
        forme.Add(new Point(340, 264));
        forme.Add(new Point(350, 259));
        forme.Add(new Point(356, 256));

            int width =  Math.Abs(forme[0].X - forme[forme.Count - 1].X);
            int height =  Math.Abs(forme[0].Y - forme[forme.Count - 1].Y);

            int halfWidth = width / 2; int halfHeigh = height / 2;

            double pmax = Math.Sqrt((width * width) + (height * height));
            double tmax = Math.PI * 2;

            // step sizes
            double dp = pmax / (double)width;
            double dt = tmax / (double)height;

            int[,] A = new int[width , height]; // accumulator array

            foreach (Point p in forme)
            { 

               for (int Theta = 1; Theta < height; Theta++)
                        {
                            double radius = ((double)(p.X) * Math.Cos(dt * (double)Theta)) + ((double)(p.Y) * Math.Sin(dt * (double)Theta)) ;

                            int k = (int)((radius / pmax) * width);
                            if (k >= 0 && k < width) A[k, Theta]++;
                        }

            }
            int goodTheta = 0;
            int goodRadius = 0;

            // maxMapIntensity c'est l'intensité maximale
            int maxMapIntensity = 0;
            for (int radius = 0; radius < width; radius++)
            {
                for (int theta = 0; theta < height; theta++)
                {
                    if (A[radius, theta] > maxMapIntensity)
                    {
                        maxMapIntensity = A[radius, theta];
                        goodRadius = radius;
                        goodTheta = theta;
                    }
                 }
            }

So, up to my understanding, i have now found the theta and radius of the intersecting point of all the curves. Then how can i find the real line ?

Some claim that I need to find the slope and a point, but it is really not clear to me what to do now.

Thanks for help, Jonathan

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

安穩 2024-08-11 22:10:11

“maxMapIntensity”代码正在查找霍夫输出中单个最亮点的坐标,因此这只会找到一条线(您使用一组点定义的线)。霍夫输出中的单个亮点对应于原始图像中的一条线。您正在找到一条所有这些点都经过的线。 goodRadiusgoodTheta 是您要查找的变量 - 该行的参数。

要计算原始线,您首先要计算从原点开始的切线(从原点开始,形成 goodTheta 角度,然后远离原点 goodRadius >)。然后,在这一点上,感兴趣的线(您找到的线)垂直于您刚刚创建的原点的线。在此图中,goodRadius 写为 ρgoodTheta 写为 θ

r theta 的解释 http://saadjomaa.com/projects/ht/images/image002.jpg< /a>

The "maxMapIntensity" code is finding the coordinates of the single brightest point in the Hough output, so this will only find one line (which you've defined with your set of points). A single bright spot in the Hough output corresponds to a single line in the original image. You're finding a line that all these points go through. The goodRadius and goodTheta are the variables you're looking for - the parameters of that line.

To calculate the original line, you first would calculate the tangent line starting at the origin (start at the origin, make an angle of goodTheta, and then travel away from the origin goodRadius). Then at that point, the line of interest (the one you found) is perpendicular to the line from the origin you just created. In this diagram, goodRadius is written as ρ, and goodTheta is written as θ.

explanation of r theta http://saadjomaa.com/projects/ht/images/image002.jpg

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文