Azzera filtri
Azzera filtri

How do I select a region of interest across many frames?

4 visualizzazioni (ultimi 30 giorni)
I want to select a same region interest across many frames, I also want this region to be fixed for all the frames because I want to detect the movement of a particle across these frames. I would really appreciate any assistance. Thank you

Risposte (2)

Image Analyst
Image Analyst il 1 Apr 2013
You can specify a region of interest in many ways.
You can interactively draw it using tools like roipoly(), roipolyold(), rbbox(), imrect(), or imfreehand(). You could specify a box by hard coding in the rows and columns. You could do segmentation, for example by intensity thresholding or color segmentation.
However you do it, you have a binary image that is the mask. You can get a frame of your video and then mask it with the ROI mask like this:
% Mask the image.
maskedRgbImage = bsxfun(@times, rgbImage, cast(mask,class(rgbImage)));
Here's a snippet you might find useful:
% Display image
subplot(2,2,1);
imshow(rgbImage);
% Have user freehand draw a mask in the image.
uiwait(msgbox('Draw a region with left button down. Double click inside to finish it'));
h = imfreehand();
vertices = wait(h);
% Create a binary mask
mask = createMask(h);
subplot(2,2,2);
imshow(mask, []);
% Mask the image.
maskedRgbImage = bsxfun(@times, rgbImage, cast(mask,class(rgbImage)));
subplot(2,2,3);
imshow(maskedRgbImage);

Matt J
Matt J il 1 Apr 2013
Modificato: Matt J il 1 Apr 2013
If your frames are held in a 3D array, A, and M is the logical mask for your ROI, you can do
B=reshape(A,[],size(A,3));
ROIs = B(M,:);
Now, ROIs(:,i) contains the ROI data the i-th frame.

Community Treasure Hunt

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

Start Hunting!

Translated by