霍夫变换问题 [英] Hough Transform question

查看:145
本文介绍了霍夫变换问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用C#以这种方式实现了Hough Transform:

  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;

//步长
double dp = pmax /(double)width;
double dt = tmax /(double)height;

int [,] A = new int [width,height]; //累加器数组

foreach(Forme中的点p)
{

for(int Theta = 1; Theta height; Theta ++)
{
double radius =((double)(pX)* Math.Cos(dt *(double)Theta))+((double)(pY)* Math.Sin(dt *(double)Theta));

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

}
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和半径。那么我怎么能找到真正的行?



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



感谢您的帮助,Jonathan

解决方案

maxMapIntensity是找到霍夫输出中单个最亮点的坐标,因此这将只找到一条线(您已使用点集合定义)。霍夫输出中的单个亮点对应于原始图像中的单个线。你发现一条线,所有这些点经历。 goodRadius goodTheta 是您要查找的变量 - 该行的参数。



要计算原始线,首先要计算从原点开始的切线(从原点开始,以 goodTheta 的角度,然后离开从起始 goodRadius )。然后在那一点,感兴趣的线(你发现的)垂直于刚刚创建的原点的线。在此图中, goodRadius 写为 goodTheta 写为 >


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

解决方案

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

这篇关于霍夫变换问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆