I want to find lines in image, but with some images, I think I find wrong lines. I use HoughLineTransform from AFroge.net
For example, in this image, I don't understand why there are diagonal lines :

With another image and the same relative intensity for houghLineTransform I find right lines :

The edge image seams to be good :

To convert polar coordinate to cartesian coordinate, I use this constructor of my own Line Class :
- Code: Select all
public Line (double theta, int radius, int imageWidth, int imageHeight)
{
int r = radius;
double t = theta;
int w2 = imageWidth /2;
int h2 = imageHeight / 2;
if ( r < 0 )
{
t += 180;
r = -r;
}
t = ( t / 180 ) * Math.PI;
double coeffAHough = -Math.Cos(t) / Math.Sin(t);
this.constB = r / Math.Sin(t);
double x0 = 0, x1 = 0, y0 = 0, y1 = 0;
if (Math.Abs (coeffAHough) >= 0 && Math.Abs (coeffAHough) <= 1) //droite plus horizontale que verticale // critère d'optimisation sur X, on fixe X = 0 pour le point1 et X = width pour le point2
{
x0 = -w2; // car hough se base sur un repère dont l'origine est le centre de l'image
x1 = w2;
y0 = ( -Math.Cos( t ) * x0 + r ) / Math.Sin( t );
y1 = ( -Math.Cos( t ) * x1 + r ) / Math.Sin( t );
}
else // la droite est plus verticale qu'horizontale // critère d'optimisation sur Y, on fixe Y = 0 pour le point1 et Y=height pour point2
{
y0 = h2;
y1 = -h2;
if(theta == 0.0) // strictement verticale
{
//Console.WriteLine("STRICT VERT");
x0 = radius;
x1 = x0;
}
else
{
//Console.WriteLine("PAS STRICT VERT");
x0 = ( -y0 * Math.Sin( t ) + r ) / Math.Cos( t );
x1 = ( -y1 * Math.Sin( t ) + r ) / Math.Cos( t );
}
}
this.p1 = new Point( (int) x0 + w2, h2 - (int) y0);
this.p2 = new Point( (int) x1 + w2, h2 - (int) y1);
}
So my question is : why do I have diagonal lines in the first image ?
Thanks