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

4 次查看(过去 30 天)
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

回答(2 个)

Image Analyst
Image Analyst 2013-4-1
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 2013-4-1
编辑:Matt J 2013-4-1
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