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

조회 수: 2 (최근 30일)
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 used the 'bwlabel' and 'regionprops' functions to crop an original image to find my region of interest (ROI).
im = imread('LA_shape1.jpg');
LA = im2bw(im, graythresh(im));
[Clab num] = bwlabel(LA);
props = regionprops(Clab);
LABox = imcrop(LA,[props.BoundingBox]);
figure; imshow(LABox);
Here is the result after cropping:
Is there any one who can kindly help me to find the coordinates of two corner points without using ginput? Thanks so much!

채택된 답변

Image Analyst
Image Analyst 2014년 12월 7일
No need to crop, label, call regionprops. Why bother if all you want are the endpoints? Simply use bwmorph()
skelImage = bwmorph(binaryImage, 'skel', inf);
endPoints = bwmorph(skelImage, 'Endpoints');
[rows, columns] = find(endPoints);
  댓글 수: 3
Image Analyst
Image Analyst 2014년 12월 7일
It looks like there are actually 2 endpoints per endpoint. That's because when you skeletonize a rectangle, you get s branch going into each corner. Zoom in and you'll see what I mean. I think it would be fine to just average the x and y points to get one point that is halfway in between the two points.
Ivan Shorokhov
Ivan Shorokhov 2015년 1월 21일
편집: Ivan Shorokhov 2015년 1월 21일
Thank you, I did as you suggested!
But what if I have a lot of endpoints, as in the following case, what can I do to find coordinates of two corner points?
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*');

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by