How to create ROI object handle?

5 ビュー (過去 30 日間)
Xingwang Yong
Xingwang Yong 2022 年 9 月 30 日
コメント済み: Xingwang Yong 2022 年 10 月 5 日
h = figure;
imshow(imread('pout.tif'));
imrect();
hg = findobj(h,'Type','hggroup')
% How can I "create" a ROI object so that I can call createMask()?
I'm trying to get ROI object handle, but it seems that it can not be retrieved after creation. Through property inspector, I found hggroup might be related to it. However, it is not the same as the handle returned by imrect().
Can I use hg to create a handle so that I can call createMask()?
Edit:
The main problem is that I have to get the ROI object after its creation. In my application, the ROI creation is done in a callback, thus I can not get an output from it. So I need to find out information about ROI object from figure handle.

回答 (3 件)

Eric Delgado
Eric Delgado 2022 年 9 月 30 日
figure;
imshow(imread('pout.tif'));
% Directly draw your rectangle using your mouse:
roi = drawrectangle;
% Draw your rectangle programmatically:
% roi = images.roi.Rectangle(gca,'Position',[x,y,W,H]);
  4 件のコメント
Xingwang Yong
Xingwang Yong 2022 年 10 月 3 日
Thanks for your clarification. It seems it is not possible to go back to h given that I only have h.h_group. I hesitated to migrate to drawrectangle() because my application use old-style imrect() intensively. It might take me some time to do the migration.

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


Image Analyst
Image Analyst 2022 年 10 月 3 日
Try this:
h = figure;
imshow(imread('pout.tif'));
uiwait(helpdlg('Drag out a box'))
rRect = imrect();
pos = rRect.getPosition
mask = rRect.createMask;
figure;
imshow(mask)
  7 件のコメント
Xingwang Yong
Xingwang Yong 2022 年 10 月 5 日
Yes, Simon's method would fail when facing sophiscated ROIs, e.g. freehand. If I can not gather enough info from figure handle, saving a variable is the only way that works.

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


Simon Chan
Simon Chan 2022 年 10 月 3 日
You may try the following:
h = figure;
imshow(imread('pout.tif'));
imrect(); % not use the output of imrect()
ax=gca;
hAx=findobj(ax.Children,'-regexp','Tag','corner marker');
x = cat(1,hAx.XData);
y = cat(1,hAx.YData);
roi = [min(x) min(y), max(x)-min(x) max(y)-min(y)]
  3 件のコメント
Xingwang Yong
Xingwang Yong 2022 年 10 月 3 日
Yes. Although this is a little bit tedious, at least it works. Thank you Simon.

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

タグ

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by