MATLAB: How to find approximate coordinates of two corner points in an image without using ginput

digital image processingimageimage analysisimage processingImage Processing Toolbox

Dear all,
I have two corner points (I marked them in red so you can see it) in black and white image. I want to find coordinates of the points automatically without using 'ginput'.
I have tried to use bwmorph(), but it gives too many endpoints as show bellow:
Code:
clear all; clc; close all; workspace; format long g; format compact;
im = imread('LA.jpg');
figure; imshow(im,[]);
LA= im2bw(im, graythresh(im));
% Filtering from noize by measuring blow
[Clab num] = bwlabel(LA);
props = regionprops(Clab);
% [maxValue,index] = max([props.Area]);
CC = bwconncomp(LA);
[~,idx] = max(cellfun(@numel,CC.PixelIdxList));
L=labelmatrix(CC);
LA=L==idx;
figure; imshow(LA);
skelImage = bwmorph(LA, 'skel', inf); %
endPoints = bwmorph(skelImage, 'Endpoints'); %
[rows, columns] = find(endPoints); % Find coordinates of the End Points
figure; imshow(LA); hold on;
plot(columns,rows,'g*');
Thank you very much for any guidance or advice you could give me.
Regards,
Ivan

Best Answer

What I would do is to get all coordinates of the boundary using bwboundaries(), then get the subset that is on the convex hull using convhull(). Then use improfile() to get values between pairs of points. If you have only one bay, then there should be only one profile where the mean of the profile is less than 1. If you have nultiple bays, then there will be lots of them. I guess you can then just take the longest one because it would extend across the longest bay. It's not too hard - the only tricky part is that you have to tack on the first point to the end of the array so that you can span the distance between the first point that convhull gives you and the last point.
boundaries = bwboundaries(binaryImage);
x = boundaries{1}(:, 2);
y = bwboundaries{1}(:, 1);
[xch, ych] = convhull(x, y);
xch = [xch, xch(1)];
ych = [ych, ych(1)];
for p = 1 : length(xch)-1
profile = improfile([xch(p), xch(p+1)], [ych(p), ych(p+1)], 100);
meanGL(p) = mean(profile);
distances(p) = sqrt((xch(p)-xch(p+1))^2 + (ych(p) - ych(p+1))^2);
% More code for you to keep track of the means and distances.
end
darkMeans = meanGL < 0.5;
% etc.....
See if you can finish the code - I did most of it for you.