File Exchange Pick of the Week

Our best user submissions

Subpixel Motion Estimation without Interpolation

Avi's pick of the week is Subpixel Motion Estimation without Interpolation by Stanley Chan.

When I work on video processing problems one of the tasks I perform most frequently is estimating the velocity of individual pixels in a video stream. It was while solving one of these problems that I stumbled upon Stanley Chan's submission on sub-pixel motion estimation without interpolation.

Contents

Read Input Video

Let's start by reading in a video which we'll use to estimate the motion between individual pixels from frame to frame.
vidReader = VideoReader('visiontraffic.avi','CurrentTime',11);

Setup Motion Estimation Parameters
We then setup the parameters for the motion estimation, in this case we set the block size to 8 and the pixel search limit to 10.

opts.BlockSize   = 8;
opts.SearchLimit = 10;

Estimate Motion Between First Two Frames

Now lets read the first two frames of video and and estimate the motion using the Bidirectional_ME function from the FileExchange entry.
frameRGBLast = readFrame(vidReader);
frameGrayLast = rgb2gray(frameRGBLast);
frameRGB = readFrame(vidReader);
frameGray = rgb2gray(frameRGB);
[MVx, MVy] = Bidirectional_ME(im2double(frameGray), im2double(frameGrayLast)...
            , opts);

figure;
subplot(2,2,1)
imagesc(MVx.^2);
title('Motion Field X-Direction');
axis image;
subplot(2,2,2)
imagesc(MVy.^2);
title('Motion Field Y-Direction');
axis image;
subplot(2,2,3);
imshow(frameRGBLast);
title('Previous Frame');
subplot(2,2,4);
imshow(frameRGB);
title('Current Frame');
POTW_Post_01

Quiver plot to view motion vectors

You can also view the motion vectors using a quiver plot.
figure;
quiver(MVx(end:-1:1,:), MVy(end:-1:1,:));
axis image;
title('Motion Vector Field');
POTW_Post_02

Other motion estimation techniques

The Computer Vision System Toolbox provides several other ways to do motion estimation include some variants of optical flow and block matching. To learn more type
doc vision

|
  • print

评论

要发表评论,请点击 此处 登录到您的 MathWorks 帐户或创建一个新帐户。