Azzera filtri
Azzera filtri

Real-time editable ROI with mask

1 visualizzazione (ultimi 30 giorni)
Yang LIU
Yang LIU il 22 Gen 2021
Commentato: Yang LIU il 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.

Risposta accettata

Shubham Rawat
Shubham Rawat il 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
You may use these links to know more about Callbacks and the example which I have used for this.
Hope this Helps!
  1 Commento
Yang LIU
Yang LIU il 2 Feb 2021
Thank you for your answer, I think it works well for my problem!

Accedi per commentare.

Più risposte (0)

Prodotti


Release

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by