how to fit two parallel lines
Show older comments

I have the datas(the red points in the pictures) that should be fitted into two parallel lines, do matlab have any functions that could fit multiple data to ensure the fitted lines are parallel?
Answers (2)
John D'Errico
on 26 Sep 2017
0 votes
The problem is, there are always things in here that you know, but are not telling us.
- Do you have some expectation for the distance between those two lines?
- Why do there appear to be FOUR lines, two of which appear to be fainter than the other two? The pair of spurious lines are not even parallel to the main lines that I see.
Next, assuming there are good answers to the questions I've posed, I'd start by use of image processing techniques.
1. Binarize the image, mapping red pixels to black pixels, everything else to white. (Or vice versa if you prefer.)
2. Use erosion to kill off the extraneous pixels that are alone.
The above steps may result in two or four lines, in a mainly white image.
3. Next, I might apply a Hough transform to the image. This will find lines, though they need not be parallel lines. And it may well find more than 2 lines, since we can see more than two lines. It will give you estimates for the lines you see.
Finally, I might choose to refine the lines so extracted, perhaps using information that you have about the expected lines, and the expected distance between them. This might involve regression methods, if you extract the pixel coordinates. It might involve various statistical methods. You can probably work with the Hough transform tools in the IPT to do much of the work. (I'm not an expert with the IPT.) But the above steps will get you a great deal of the way to a solution.
Categories
Find more on 图像变换 in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!