How to find approximate coordinates of two corner points in an image without using ginput?
3 views (last 30 days)
Show older comments
Ivan Shorokhov
on 22 Jan 2015
Commented: Ivan Shorokhov
on 23 Jan 2015
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
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.
Accepted Answer
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
More Answers (0)
See Also
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!