Real-time editable ROI with mask
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Yang LIU
am 22 Jan. 2021
Kommentiert: Yang LIU
am 2 Feb. 2021
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 Kommentare
Akzeptierte Antwort
Shubham Rawat
am 2 Feb. 2021
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!
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!