MATLAB Answers

How to extract diagonal line data from image

32 views (last 30 days)
ridethelightning on 10 Nov 2019
Commented: Image Analyst on 11 Nov 2019
I am having some difficult attempting to extract point data from a set of diagonal lines. The lines should be perfectly vertical, but unfortunately because of experimental parameters beyond my control, it's slightly tilted CW. It's a very simple problem but with a solution I find difficult to implement (at least I can't figure it out too well). Attached is the image I have for context with a Hough transform applied to show some lines. X and Y axes are pixel counts (the whole image is the total size of the CCD chip). The Hough transform procedure to see the lines only give me the end points, which is obviously not sufficient.
Naturally it would be easy if the lines were aligned along the Y axis on an XY axis plot, just take all the points along Y for a single X value. But doing it diagonally seems to make the problem extremely more difficult. One would just think of getting the data along the appropriate Y = m*X + b line, but if the slope m is super steep, that would mean I need much more resolution along X to properly resolve Y if it were vertical.
How would I be able to apply an algorithm such that the line drawn along the plot would be able to capture most if not all the points that would be if the lines were vertical? Maybe the Hough transform procedure has this info stored and I just need to extract it? Any assistance would be really appreciated!


Sign in to comment.

Answers (2)

Stephan on 10 Nov 2019
Edited: Stephan on 10 Nov 2019
The result for every line object contains an information about the angle of the line. This information can be used as input to imrotate to get an image having vertical lines.
To learn how to get the angle you could use this example.

  1 Comment

ridethelightning on 11 Nov 2019
I can't believe I didn't think of doing that. This might actually be sufficient for what I need! Thank you, I'll try it and if there's any more trouble, I'll be sure to come back with some questions.

Sign in to comment.

Image Analyst
Image Analyst on 10 Nov 2019
Edited: Image Analyst on 10 Nov 2019
Your image is a perfect place where the radon transform would be used. Basically the radon transform rotates the image through a series of angles that you specify to get projections. Then you get an image with distance versus angle. You can look at each angle (column) in the image to find out which angle gives the brightest average value by taking the mean along the rows to get the mean for each column. The column (i.e. angle) with the brightest mean is the angle you want. I'm attaching a demo, which uses the football demo image not yours, but you can easily adapt it.


ridethelightning on 11 Nov 2019
Thank you for providing info about the Radon transform (as well as an example code), I didn't know there was an alternative to the Hough transform in Matlab. I'll compare the two methods and see which one fits my objectives the most.
Image Analyst
Image Analyst on 11 Nov 2019
Well, most people wouldn't think of it. Maybe that's why they won a Nobel prize for it - figuring out how to do CT using the Radon Transform.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!