Real-time editable ROI with mask
조회 수: 1 (최근 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!