views:

582

answers:

2

Hi

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

A: 

Take a look at this wikipedia article, it explains it and links to some sample Java code that you could probably learn a lot from.

Hope this helps!

Timothy Walters
+1  A: 
endolith