# How to apply masks created by roipoly to movie?

6 Ansichten (letzte 30 Tage)
MF am 27 Feb. 2022
Bearbeitet: AndresVar am 27 Feb. 2022
I'm having issues understanding roipoly in general, so apologies if this is rudimentary and if I am making extremely basic errors.
I am trying to create four masks using roipoly in a forloop for one image (four areas of interest). After, I would like to create another loop inside this one that extracts pixel intensities in each ROI for each frame in a movie object and store this in a matrix (columns = # pixels in ROI, rows = pixel values for each frame).
Here is the code I have so far. It is extremely minimal, despite looking for similar questions here and watching tutorials. If anyone could advise a resource or solution, it would be greatly appreciated.
for i = 1:4
cell(i) = roipoly(I); % where 'I' is the image
% This doesn't appear to save four masks. Am I making a careless error?
for j = 1:length(movie)
% How would I create a matrix that stores pixel values?
end
end
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Antworten (2)

Image Analyst am 27 Feb. 2022
cell is a built-in function so don't use it as a variable name. The results of roipoly are not a single number. You need to use poly2mask() and then OR it with the main mask like
then in the loop get your (x,y) coordinates from drawfreehand() or impoly() or whatever and then get the mask and OR it in
If you still can't figure it out after trying, write back with your new code.
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

AndresVar am 27 Feb. 2022
Bearbeitet: AndresVar am 27 Feb. 2022
You can store the roipoly result in a cell array like this
rois = cell(1,4)
for ii = 1:4
rois{ii} = roipoly(I);
end
Would it better to do get pixelvalues in a separate loop? otherwise you have to wait until movie is done collecting before you can get a new mask.
Also the pixelvalues matrix will be n-by-1, where n is the number of pixel in the ROI
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu ROI-Based Processing finden Sie in Help Center und File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by