Page 1 of 1

HoughLine, wrong lines? Posted: Wed Apr 24, 2013 9:29 pm
Hello,
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)
{
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");
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

Re: HoughLine, wrong lines? Posted: Thu Apr 25, 2013 8:48 am
Hello,

Check documentation and see that this class is looking for WHITE lines on BLACK background. So I am not sure what you expect when giving it a document with white background.

P.S. Your topic has nothing to do with IPLab. Read boards' descriptions before posting.

Re: HoughLine, wrong lines? Posted: Thu Apr 25, 2013 9:01 am
Hello, and thank you for your answer. I give a edge image (with white line : same as in the post) to the HoughLineTransform.