Real-time editable ROI with mask
3 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
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
Hope this Helps!
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!