Detect endpoints of a line

Viewed 146

I want to detect the points shown in the image below:

Image Link

I have done this so far:

[X,map] = rgb2ind(img,0.0);
img = ind2gray(X,map);    % Convert indexed to grayscale
level = graythresh(img);   % Compute an appropriate threshold
img_bw = im2bw(img,level);% Convert grayscale to binary
mask = zeros(size(img_bw));
mask(2:end-2,2:end-2) = 1;
img_bw(mask<1) = 1;
%invert image
img_inv =1-img_bw;
% find blobs
img_blobs = bwmorph(img_inv,'majority',10);
% figure, imshow(img_blobs);
[rows, columns] = size(img_blobs);
for col = 1 : columns
    thisColumn = img_blobs(:, col);
    topRow = find(thisColumn, 1, 'first');
    bottomRow = find(thisColumn, 1, 'last');
    img_blobs(topRow : bottomRow, col) = true;
end
inverted = imcomplement(img_blobs);
ed = edge(inverted,'canny');
figure, imshow(ed),title('inverted');

Now how to proceed to get the coordinates of the desired position?

2 Answers
Related