__1. Reading image__

clear all;clc;

I = imread('pic24.jpg');

I = im2bw(I);

imshow(I);

__2. Finding all the pixels with the value of '1'__

[y,x] = find(I==1);

imshow(I);

hold on;

plot(x,y);

__3. Use the "polyfit" function to fit polynomial to data, in our case, since it is a straight line, we use 1st order polynomial or a linear equation Y = M*X + C__

p = polyfit(x,y,1);

disp(p);

-0.7873 158.3164

__4. Find the image size and create the X and Y based on the coefficients of "p".__

sz = size(I);

X = 1:sz(2);

Y = p(1) * X + p(2);

__5. Display the result__

imshow(I);

hold on;

plot(X,Y);