Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

extract lines from canny edge detection

In openCV after applying canny edge detection I'd like to further process the result (show only horizontal lines, remove short lines, etc..). But the result of canny is just another image. I'd like to get an array of lines describing the detected edges

I'm aware of the famous Hough Line Transform, but the result is not always good, that's why I'd like to manually process canny result. input:

enter image description here

output canny only:

enter image description here

output canny then Hough line transform

enter image description here

This is Hough line transform result(red lines) for detecting edges of stairs. 4th line from below is not detected correctly, although canny edge detected an edge.

Any idea how to extract edges from canny image?

like image 383
Moataz Elmasry Avatar asked Jun 05 '12 07:06

Moataz Elmasry


People also ask

How do I find the lines of an image in Python?

Use the HoughLinesP() Function of OpenCV to Detect Lines in an Image in Python. The HoughLinesP() function uses probabilistic Hough line transform to detect lines. We have to read the given image using the imread() function, convert it into grayscale, and then find its edges using Canny() .

Is edge detection feature extraction?

Edge detection is one of the steps used in image processing. It can be used for both feature extraction to detect objects and for verifying pixel integrity of two images.

Is Canny edge detector linear?

The Canny edge detector is a linear filter because it uses the Gaussian filter to blur the image and then uses the linear filter to compute the gradient.

Why is Sobel better than Canny?

The main advantages of the Sobel operator are that it is simple and more time-efficient. However, the edges are rough. On the other hand, the Canny technique produces smoother edges due to the implementation of Non-maxima suppression and thresholding.


1 Answers

A few things you can try to improve your results:

Apply a Region of Interest

Your image looks to have some bordering window effects. I removed them with a region of interest resulting in an image that looks like this (I tweaked it until it looked right, but if you're using some kind of kernel operator it's window size probably better defines this ROI):

enter image description here

Use standard Hough transform

It also seems you're using the probabilistic Hough transform. So, you're only getting line segments instead of an interpolated line. Consider using the standard transform to get the full theoretical line (rho, theta). Doing this I got an image like shown below:

enter image description here

Here is a code snippet I used to generate the lines (from Python interface):

(mu, sigma) = cv2.meanStdDev(stairs8u)
edges = cv2.Canny(stairs8u, mu - sigma, mu + sigma)
lines = cv2.HoughLines(edges, 1, pi / 180, 70)

Filter lines based on angle

You can probably filter out poor lines by taking the most frequently occurring line angles, and throwing away outliers. This should narrow it down to the most visible steps.

Hope that helps!

like image 147
mevatron Avatar answered Oct 11 '22 09:10

mevatron