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.


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);

title('Motion Field X-Direction');
axis image;
title('Motion Field Y-Direction');
axis image;
title('Previous Frame');
title('Current Frame');

Quiver plot to view motion vectors

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

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
  • send email


To leave a comment, please click here to sign in to your MathWorks Account or create a new one.