How to get matrix indices from roipoly
古いコメントを表示
I have a matrix that I want to extract an ROI from. I am using roipoly to clip the region. The syntax below gives the coordinates of the polygon in the intrinsic coordinate system, I believe. How can I get the matrix indices for each vertex of the polygon?
tst = rand(100);
[xrefout,yrefout,BW,xi2,yi2] = roipoly(tst);
I select some square.
xi2 and yi2 are real valued. To get the pixel value, does one just round xi2 and yi2 to the nearest integer?
採用された回答
その他の回答 (1 件)
Image Analyst
2021 年 9 月 10 日
Try using the mask roipoly() returns:
tst = imread('moon.tif'); % Get some matrix.
imshow(tst); % Display it.
% Ask user to use roipoly.
message = sprintf('Left click vertices.\nRight click last point.\nThen double click inside when you are all done.');
uiwait(helpdlg(message));
mask = roipoly(tst);
% Extract values inside the polygon they drew.
valuesInsideMask = tst(mask)
4 件のコメント
Paul Safier
2021 年 9 月 10 日
Image Analyst
2021 年 9 月 11 日
Why do you need only the vertices? What will you do then, once you have them? Nothing further?
Paul Safier
2021 年 9 月 11 日
Image Analyst
2021 年 9 月 11 日
There is also a drawpolygon() function that you might like.
カテゴリ
ヘルプ センター および File Exchange で ROI-Based Processing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!