File Exchange

image thumbnail

Affine optic flow

version (1.03 MB) by David Young
Estimates the parameters of an affine (first-order) optic flow model from two images.


Updated 04 Mar 2016

View Version History

View License

An affine (or first-order) optic flow model has 6 parameters, describing image translation, dilation, rotation and shear. The class affine_flow provides methods to estimates these parameters for two frames of an image sequence.
The class implements a least-squares fit of the parameters to estimates of the spatial and temporal grey-level gradients. This is an extension of the well-known Lucas-Kanade method. The images are either sampled conventionally, on a rectilinear grid, or on a log-polar grid. In the latter case, the class may iteratively refine its estimates by moving the sampling grid to track the motion. Options to specify a region of interest and smoothing and sampling parameters are provided.
The file includes a demonstration of the class, and test images for this. The functions for smoothing images and estimating gradients may be useful independently, and log-polar sampling functions are included (and are available separately in submission 27023).

Cite As

David Young (2021). Affine optic flow (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (9)


Can you please provide any reference upon which this work is based? It will be very helpful for me. Thanks

David Young

Avi: Thank you. And yes, I would always recommend trying the MathWorks toolbox first if it is available.

Avi Nehemiah

Thanks for the great submission.

The Computer Vision System Toolbox now includes optical flow in MATLAB.

Check out this link for information and code examples on optical flow:


Works great!

David Young

The Matlab OOP capabilities were introduced with version 2008a, so yes, I think it should work with 2009a. It's worth trying, and if there are problems they should be minor ones that can be fixed. For example you may need to replace '~' as an unused argument or result with a variable name such as 'unused'.

Alfian Abdul Halin

The time I ran this I was using MATLAB 2007... you think it might work if I use R2009a?

David Young

Alfian: What Matlab version are you using? It may be the problem: this class uses the fairly recent Matlab OO system, and was tested in version 2010a.

Alfian Abdul Halin

Hi. I tried to run the demo code (with Jpeg images)... and got this error (but i think its not due to the jpegs)...

??? Error: File: affine_flow.m Line: 1 Column: 10
A class definition must be in an "@" directory.

Glen Lichtwark

MATLAB Release Compatibility
Created with R2016a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!