# jitterImage

## PURPOSE

Creates multiple, slightly jittered versions of an image.

## SYNOPSIS

function IJ = jitterImage( I, varargin )

## DESCRIPTION

     Creates multiple, slightly jittered versions of an image.

     Takes an image I, and generates a number of images that are copies of the
     original image with slight translation, rotation and scaling applied. If
     the input image is actually an MxNxK stack of images then applies op to
     each image. Rotations and translations are specified by giving a range
     and a max value for each. For example, if mPhi=10 and nPhi=5, then the
     actual rotations applied are linspace(-mPhi,mPhi,nPhi)=[-10 -5 0 5 10].
     Likewise if mTrn=3 and nTrn=3 then the translations are [-3 0 3]. Each
     tran is applied in the x direction as well as the y direction. Each
     combination of rotation, tran in x, tran in y and scale is used (for
     example phi=5, transx=-3, transy=0), so the total number of images
     generated is R=nTrn*nTrn*nPhi*nScl. Finally, jsiz controls the size of
     the cropped images. If jsiz gives a size that's sufficiently smaller than
     I then all data in the the final set will come from I. Otherwise, I must
     be padded first (by calling padarray with the 'replicate' option).

     USAGE
      function IJ = jitterImage( I, varargin )

     INPUTS
      I          - image (MxN) or set of K images (MxNxK)
      varargin   - additional params (struct or name/value pairs)
       .maxn        - [inf] maximum jitters to generate (prior to flip)
       .nPhi        - [0] number of rotations
       .mPhi        - [0] max value for rotation
       .nTrn        - [0] number of translations
       .mTrn        - [0] max value for translation
       .flip        - [0] if true then also adds reflection of each image
       .jsiz        - [] Final size of each image in IJ
       .scls        - [1 1] nScl x 2 array of vert/horiz scalings
       .method      - ['linear'] interpolation method for imtransform2
       .hasChn      - [0] if true I is MxNxC or MxNxCxK

     OUTPUTS
      IJ          - MxNxKxR or MxNxCxKxR set of images, R=(nTrn^2*nPhi*nScl)

     EXAMPLE
      load trees; I=imresize(ind2gray(X,map),[41 41]); clear X caption map
      % creates 10 (of 7^2*2) images of slight trans
      IJ = jitterImage(I,'nTrn',7,'mTrn',3,'maxn',10); montage2(IJ)
      % creates 5 images of slight rotations w reflection
      IJ = jitterImage(I,'nPhi',5,'mPhi',25,'flip',1); montage2(IJ)
      % creates 45 images of both rot and slight trans
      IJ = jitterImage(I,'nPhi',5,'mPhi',10,'nTrn',3,'mTrn',2); montage2(IJ)
      % additionally create multiple scaled versions
      IJ = jitterImage(I,'scls',[1 1; 2 1; 1 2; 2 2]); montage2(IJ)
      % example on color image (5 images of slight rotations)
      I=imResample(imread('peppers.png'),[100,100]);
      IJ=jitterImage(I,'nPhi',5,'mPhi',25,'hasChn',1);
      montage2(uint8(IJ),{'hasChn',1})

     See also imtransform2

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