I want to fit a line to line fragments, i.e. a small number (often less than 10) of line segments that approximately belong to the line. The line has a small slope. But there are outliers: segments (usually smaller) outside the line. The figure below shows a typical case. There is no horizontal overlap between the pieces.
I would prefer to avoid trying a fit on all subsets of segments and keeping the best. I also wouldn't rely on RANSAC as the sample is too small.
Any suggestion ?
Update:
I now plan to recast the problem as that of fitting a line on points, namely the infinities of points on the individual line segments, assuming a constant linear density. By rewriting the least squares equations in integral form, one sees that we can consider the segments as concentrated at their middle, with a weight equal to their length; there is also an extra term taking their slope into account. This gives a good grounding to the fitting on segments.
Now I still have to incorporate outlier detection. Inspired by RANSAC, I can pick the longest segments and use them in isolation or in pairs to get candidate lines. For each line, evaluate the total error, and keep the line giving the smallest value. From there, some criterion (yet to be found) should allow rejecting the outliers and performing the final least-squares fit on the inliers.