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 계정에 로그인하거나 계정을 새로 만드십시오.