# imagesAlignSeq

## PURPOSE

Stabilize image sequence using coarse optical flow estimation.

## SYNOPSIS

function [J,Vxs,Vys] = imagesAlignSeq( I, pFlow, type, bndThr )

## DESCRIPTION

     Stabilize image sequence using coarse optical flow estimation.

     Perform weak image sequence stabilization as described in:
      D. Park, C. Zitnick, D. Ramanan and P. Dollár
      "Exploring Weak Stabilization for Motion Feature Extraction", CVPR 2013.
     The approach stabilizes coarse motion due to camera movement but leaves
     independent object motions intact. This code performs weak sequence
     stabilization only (no feature extraction), see section 3.1 of the paper.
     Please cite the above paper if you end up using the stabilization code.

     Optical flow is computed between all pairs of frames using opticalFlow.m
     with params 'pFlow'. Flow across multiple frames is accumulated and flow
     at integer locations at each stage is obtained either using either
     nearest neighbor (if type==1) or bilinear interpolation (if type==2)
     which is slightly more accurate but slower. Finally, all images in I are
     warped to the last frame of the sequence using the accumulated flows. If
     type==-1, a homography computed via imagesAlign.m with params pFlow is
     used instead. If videos have black boundaries use bndThr to ignore dark
     boundaries for flow estimation (with average pixel values under bndThr).

     USAGE
      [J,Vxs,Vys] = imagesAlignSeq( I, pFlow, [type], [bndThr] )

     INPUTS
      I          - HxWxN or HxWx3xN input image sequence
      pFlow      - parameters to use for optical flow computation
      type       - [1] interpolation type 1:nearest, 2:bilinear
      bndThr     - [0] fill in black areas around image boundaries

     OUTPUTS
      J          - HxWxN or HxWx3xN stabilized image sequence
      Vxs        - HxWxN-1 x-components of flow fields
      Vys        - HxWxN-1 y-components of flow fields

     EXAMPLE
      I = seqIo(which('peds30.seq'),'toImgs'); I=I(:,:,:,1:15);
      pFlow={'smooth',1,'radius',25,'type','LK','maxScale',1};
      tic, J = imagesAlignSeq( I, pFlow, 1, 20 ); toc
      playMovie([I J],15,-10,struct('hasChn',1))

     EXAMPLE
      % Requires Caltech Pedestrian Dataset to be installed
      [pth,ss,vs]=dbInfo; s=randi(length(ss)); v=randi(length(vs{s}));
      nm=sprintf('%s/videos/set%02i/V%03i.seq',pth,ss(s),vs{s}(v));
      f=seqIo(nm,'getinfo'); f=f.numFrames; f=randi(f-30);
      I=seqIo(nm,'toImgs',[],1,f,f+9);
      pFlow={'smooth',1,'radius',25,'type','LK','maxScale',1};
      tic, J = imagesAlignSeq( I, pFlow, 1, 20 ); toc
      playMovie([I J],15,-10,struct('hasChn',1))

     See also opticalFlow, imtransform2, imagesAlign

     Piotr's Image&Video Toolbox      Version 3.24
     Copyright 2013 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]