


Coarse-to-fine optical flow using Lucas&Kanade or Horn&Schunck.
Implemented 'type' of optical flow estimation:
LK: http://en.wikipedia.org/wiki/Lucas-Kanade_method
HS: http://en.wikipedia.org/wiki/Horn-Schunck_method
LK is a local, fast method (the implementation is fully vectorized).
HS is a global, slower method (an SSE implementation is provided).
Common parameters for LK and HS: 'smooth' determines smoothing prior to
flow computation and can make flow estimation more robust. 'resample' can
be used to downsample an image for faster but lower quality results, e.g.
resample=.5 makes flow computation about 4x faster. LK: 'radius' controls
integration window size (and smoothness of flow). HS: 'alpha' controls
tradeoff between data and smoothness term (and smoothness of flow) and
'nIter' determines number of gradient decent steps.
USAGE
[Vx,Vy,reliab] = opticalFlow( I1, I2, pFlow )
INPUTS
I1, I2 - input images to calculate flow between
pFlow - parameters (struct or name/value pairs)
.type - ['LK'] may be either 'LK' or 'HS'
.smooth - [1] smoothing radius for triangle filter (may be 0)
.resample - [1] resampling amount (must be a power of 2)
.radius - [5] integration radius for weighted window [LK only]
.alpha - [1] smoothness constraint [HS only]
.nIter - [250] number of iterations [HS only]
OUTPUTS
Vx, Vy - x,y components of flow [Vx>0->right, Vy>0->down]
reliab - reliability of flow in given window [LK only]
EXAMPLE - compute LK flow on test images
load opticalFlowTest;
[Vx,Vy]=opticalFlow(I1,I2,'smooth',1,'radius',10,'type','LK');
figure(1); im(I1); figure(2); im(I2);
figure(3); im([Vx Vy]); colormap jet;
EXAMPLE - rectify I1 to I2 using computed flow
load opticalFlowTest;
[Vx,Vy]=opticalFlow(I1,I2,'smooth',1,'radius',10,'type','LK');
I1=imtransform2(I1,[],'vs',-Vx,'us',-Vy,'pad','replicate');
figure(1); im(I1); figure(2); im(I2);
EXAMPLE - compare LK and HS flow
load opticalFlowTest;
prm={'smooth',1,'radius',10,'alpha',20,'nIter',200,'type'};
tic, [Vx1,Vy1]=opticalFlow(I1,I2,prm{:},'LK'); toc
tic, [Vx2,Vy2]=opticalFlow(I1,I2,prm{:},'HS'); toc
figure(1); im([Vx1 Vy1; Vx2 Vy2]); colormap jet;
See also convTri, imtransform2
Piotr's Image&Video Toolbox Version 3.02
Copyright 2012 Piotr Dollar. [pdollar-at-caltech.edu]
Please email me if you find bugs, or have suggestions or questions!
Licensed under the Simplified BSD License [see external/bsd.txt]