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

1 view (last 30 days)
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
  2 Comments
Ashish Uthama
Ashish Uthama on 23 Jan 2015
Edited: Ashish Uthama on 23 Jan 2015
Are you looking for an approach which just works on this one image? If not, are there any characteristics of these images that you can share? For example, is the white area always oriented as above? Is it roughly always in the same part of the image? Is it always the same size? Is there anything else in the raw (original image) which would help you? etc.. this kind of information would be very useful to figure out a way which would really solve your problem.
Ivan Shorokhov
Ivan Shorokhov on 23 Jan 2015
Edited: Ivan Shorokhov on 23 Jan 2015
Dear Ashish,
Thank you, for your interest!
I'm looking for an approach to find two corner points in an image with following characteristics:
  • 1. Orientation is unknown.
  • 2. Shape is similar to above, it could have U/V shape, sometimes open U, i.e. it looks like 2 brackets: ( ).
  • 3. Image is roughly near center.
  • 4. Size may vary, but not a lot.
If you have any other comments, please leave them bellow.
Best Regards,
Ivan

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 23 Jan 2015
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.
  3 Comments
Ivan Shorokhov
Ivan Shorokhov on 23 Jan 2015
Edited: Ivan Shorokhov on 23 Jan 2015
Dear Image Analyst,
Thank you very much for such an open answer.
I was thinking about using 'orientation line' and start looking for first values before NaN, the result looks as follows:
Small part of the code, to make my messy explanation little bit more clear:
for r1=1:ycent-ymin
rlr(:,:,r1) =fliplr(bi(ycent-r1+1, xmin:(xcent-1)));
if isempty(find(rlr(:,:,r1), 1,'first'))
lr1=find(rlr(:,:,r1-1), 1,'first');
x2=xcent-lr1+1; y2=ycent-r1; plot(x2, y2, 'go');
break
end
end
But my full code has a lot of 'for' and 'if' loops, so I will defiantly try your algorithm!
As usual thanks a lot!
Ivan Shorokhov
Ivan Shorokhov on 23 Jan 2015
Dear Image Analyst,
When I was trying to run your code, I received following error:
Error using horzcat
Dimensions of matrices being concatenated are not consistent.
Error in u_seg (line 48)
xch = [xch, xch(1)];
So I not sure what meat by this line: xch = [xch, xch(1)];
Where: xch = 1 7 12 . . . 713 1
And obviously xch(1) = 1,
So the length of xch and xch(1) are not the same.
Also I assume you made small typo
y = bwboundaries{1}(:, 1);
I guess it should be simply:
y = boundaries{1}(:, 1);
If I'm wrong please let me know.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!