Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the use of Canny before HoughLines (opencv)?

I'm new to image processing and I'm working on detecting lines in a document image. I read the theory of Hough line transform but I can't see why I must use Canny before calling that function in opencv like being said in many tutorials. What's the point of finding edges in this case? The fact is that if I don't use Canny or threshold before HoughLines() the results will be very messy. I hope someone will explain for me the reason why.

2 of the tutorials I've read:

  1. Imgproc Feature Detection
  2. Hough Line Transform
like image 519
Risa Avatar asked Feb 16 '12 11:02

Risa


People also ask

What does Canny do in OpenCV?

Canny() Function in OpenCV is used to detect the edges in an image.

What is canny edge detection in image processing?

The Canny edge detector is an edge detection operator that uses a multi-stage algorithm to detect a wide range of edges in images. It was developed by John F. Canny in 1986. Canny also produced a computational theory of edge detection explaining why the technique works. ( Wikipedia)

What is cv2 HoughLines?

Everything explained above is encapsulated in the OpenCV function, cv2.HoughLines(). It simply returns an array of. values. is measured in pixels and is measured in radians. First parameter, Input image should be a binary image, so apply threshold or use canny edge detection before finding applying hough transform.

What is threshold in cv2 Canny?

Canny does use two thresholds (upper and lower): If a pixel gradient is higher than the upper threshold, the pixel is accepted as an edge. If a pixel gradient value is below the lower threshold, then it is rejected.


1 Answers

Short Answer

cvCanny is used to detect Edges, as well as increase contrast and remove image noise. HoughLines which uses the Hough Transform is used to determine whether those edges are lines or not. Hough Transform requires edges to be detected well in order to be efficient and provide meaning results.

Long Answer

The Limitations of the Hough Transform are described in more detail on Wikipedia.

The efficiency of the Hough Transform relies of the bin of acculumated pixel being distinct, e.g. a direct contrast between a pixel and its surrounding neighbours or if using a mask region a pixel region and its surrounds regions. If all pixels had similar acculumated values nothing would stand out as a line or circle. This leads to the reduction of colour (colour to grayscale, grayscale to black and white) in order to increase contract.

The number of parameters to the Hough Transform also increase the spread of votes in the pixel bins and increase the complexity of the transform, which mean that normally only lines or circles are reliably detected using it as they have less than 3 parameters.

The edges need to be detected well before running the Hough Transform otherwise its efficiency suffers further. Also noisy images don't work well with Hough transform unless the noise is removed before hand.

like image 70
Appleman1234 Avatar answered Sep 23 '22 17:09

Appleman1234