MATLAB: How can i complete the line points

estimating pointsline

I want to complete the line by connecting it to upper and lower edge/corner of the image. estimated points should follow the trajectory of line. See the attached image

Best Answer

Read the image into MATLAB, fit the line using polyfit, and then plot it:
Im = imread('image.jpg');
Ib = mean(Im,3)>128;
[R,C] = find(flipud(Ib));
coeffs = polyfit(C,R, 1);
X = 1:size(Im,2);
Y = polyval(coeffs, X);
idx = 0<Y & Y<size(Im,1);
scatter(R,C) % The pixels of the original line
hold on
plot(X(idx),Y(idx),'-xr') % the fitted line
You can play around with the colors, linewidth, marker, etc. You could also use imshow, im2bw, and the like, depending on what toolboxes you have fitted.