Extract region/outline coordinates using ginput

Hi, I have to boundary line over a coin. My question is how can I get only the region coordinates which is marked by two ginput crosshairs.
Thanks in advance.
I = imread('coins.png');
imshow(I)
BW = im2bw(I);
imshow(BW)
dim = size(BW)
col = round(dim(2)/2)-90;
row = min(find(BW(:,col)))
boundary = bwtraceboundary(BW,[row, col],'N');
imshow(I)
hold on;
plot(boundary(:,2),boundary(:,1),'b','LineWidth',2);
[x, y] = ginput(2);
plot(x, y,'r+','MarkerSize', 11);

回答 (1 件)

Image Analyst
Image Analyst 2017 年 10 月 11 日

0 投票

I'm not sure what you want to do. You can get the boundaries of all binary blobs using bwboundaries(), not bwtraceboundary():
boundaries = bwboundaries(BW);
Beyond that, I have no idea what you're trying to do by asking the user to click two points somewhere in the image.

6 件のコメント

Jane Bat
Jane Bat 2017 年 10 月 11 日
Thanks. I used two ginputs in order to mark a section in the outline and I wish to have only its coordinates. Is it possible to get a section coordinates?
Image Analyst
Image Analyst 2017 年 10 月 11 日
When you do
[x, y] = ginput(2);
x and y will each be a 2 element array with the coordinates of where you clicked.
Jane Bat
Jane Bat 2017 年 10 月 12 日
Sorry for my English as I think I was not understandable. How can I have the arc coordinates between the 2 selected ginputs?
Image Analyst
Image Analyst 2017 年 10 月 12 日
One way is to use improfile(). Another way is to use interp1().
Jane Bat
Jane Bat 2017 年 10 月 12 日
Can you please add an example script. Thank you very much
Image Analyst
Image Analyst 2017 年 10 月 12 日
Did you see the example in the documentation? Probably not. So look at it. You can get the x and y coordinates like this:
[cx,cy,c] = improfile(I)

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeData Exploration についてさらに検索

質問済み:

2017 年 10 月 11 日

コメント済み:

2017 年 10 月 12 日

Community Treasure Hunt

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

Start Hunting!

Translated by