Reputation: 2421
I have an image with multiple almost straight lines. I would like to fit the points in these straight lines using root mean square method. However, I would like multiple lines to be fit which is obvious from the image below. I have tried transforms like Hough Transform and the fitline method in python but they are giving me slightly slanting lines and this is why I thought I would go for RMS method. I know how to fit a single line to the points but is there any way I can fit 3 lines at once as required?
Upvotes: 1
Views: 846
Reputation: 77885
Clustering by slope will work unless you have target lines that are very close to parallel; in that case, you'd want to do a little more processing, such as slope/intercept pairs for each segment, and cluster those results. In any case, there's no need to repeat HoughLines.
Given that you have parallel, separated lines, I suggest that you do a little pre-processing. Do you have a ready method that allows you to approximate endpoints for your segments? If so, try doing a simple two-point formula to get (slope, intercept) pairs for those lines, and cluster those pairs. That will neatly sort the segments into proper linear sets.
If you don't have the segments identified, you might first try a spectral clustering algorithm to identify them; pick one that's strong on density and connectivity; you don't really care about gap sensitivity.
Upvotes: 2