Real-time editable ROI with mask

7 ビュー (過去 30 日間)
Yang LIU
Yang LIU 2021 年 1 月 22 日
コメント済み: Yang LIU 2021 年 2 月 2 日
Hello everyone, I'm working with data processing and I have a problem.
I have a 2-D matrix data, and I want to draw a ROI on it and see the data inside the ROI. I used 'drawpolygon' and 'createMask' to do this. To make things easier to be understood, I just put a similar code I'm using here:
a = magic(8);
imagesc(a);
b = drawpolygon;
c = createMask(b);
cc = c.*a;
d = sum(cc,[1,2]);
The problem is, I want to drag or edit the ROI and have the calculated data ('d' here) to be changed together at the same time. Which means that when I finish drawing the ROI, I will have the calculated data; and once I make change to the ROI, the calculated data changes as well. And at last I have to delete the ROI and save the mask and the calculated data. I've looked up 'addlistener' but not sure how it works.
Any help or suggestions are welcomed, thanks.

採用された回答

Shubham Rawat
Shubham Rawat 2021 年 2 月 2 日
Hi Yang,
I have reproduced your code and got the results in Real time. You may use this code to do the things:
a = magic(8);
imagesc(a);
b = drawpolygon;
%draw polygon in the figure;
l = addlistener(b,'MovingROI',@(src,evt)clickCallback(src,evt,b,a)); %this listener I have added to listen whenever we move ROI
the function for the callback is here:
function clickCallback(src,evt,b,a)
c = createMask(b);
cc = c.*a;
d = sum(cc,[1,2]);
disp(d); %displaying the values of d
end
You may use these links to know more about Callbacks and the example which I have used for this.
Hope this Helps!
  1 件のコメント
Yang LIU
Yang LIU 2021 年 2 月 2 日
Thank you for your answer, I think it works well for my problem!

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

その他の回答 (0 件)

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by