# How to apply masks created by roipoly to movie?

4 vues (au cours des 30 derniers jours)
MF le 27 Fév 2022
Modifié(e) : AndresVar le 27 Fév 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 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Réponses (2)

Image Analyst le 27 Fév 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 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

AndresVar le 27 Fév 2022
Modifié(e) : AndresVar le 27 Fév 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 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Catégories

En savoir plus sur ROI-Based Processing dans Help Center et File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by