# imtransform2

## PURPOSE

Applies a general/special homography on an image I

## SYNOPSIS

function IR = imtransform2( I, varargin )

## DESCRIPTION

     Applies a general/special homography on an image I

     Takes the center of the image as the origin, not the top left corner.
     Also, the coordinate system is row/column format, so H must be also.

     The bounding box of the image is set by the BBOX argument, a string that
     can be 'loose' (default) or 'crop'. When BBOX is 'loose', IR includes the
     whole transformed image, which generally is larger than I. When BBOX is
     'crop' IR is cropped to include only the central portion of the
     transformed image and is the same size as I. The 'loose' flag is
     currently inexact (because of some padding/cropping). Preserves I's type.

     USAGE
      IR = imtransform2( I, H, [method], [bbox], [show] )      % general hom
      IR = imtransform2( I, angle, [method], [bbox], [show] )  % rotation
      IR = imtransform2( I, dx, dy, [method], [bbox], [show] ) % translation

     INPUTS - common
      I       - 2D image [converted to double]
      method  - ['linear'] 'nearest', 'spline', 'cubic' (for interp2)
      bbox    - ['loose'] or 'crop'
      show    - [0] figure to use for optional display

     INPUTS - specific to general homography
      H       - 3x3 nonsingular homography matrix

     INPUTS - specific to rotation
      angle   - angle to rotate in degrees

     INPUTS - specific to translation
      dx      - x translation (right)
      dy      - y translation (up)

     OUTPUTS
      IR      - transformed image

     EXAMPLE - general homography (rotation + translation)
      load trees; I=X;
      R = rotationMatrix( pi/4 ); T = [1; 3]; H = [R T; 0 0 1];
      IR = imtransform2( I, H, [], 'crop', 1 );

     EXAMPLE - general homography (out of plane rotation)
      load trees; I=X;
      R = rotationMatrix( [0 1 0], pi/4 );  z=500;
      H = R; H(1:2,:)=H(1:2,:)*z; H(:,3)=H(:,3)*z;
      IR = imtransform2(I,H,'nearest','loose',1);

     EXAMPLE - rotation
      load trees;
      tic; X1 = imrotate( X, 55, 'bicubic', 'crop' ); toc,
      tic; X2 = imtransform2( X, 55, 'bicubic', 'crop' ); toc
      clf;  subplot(2,2,1); im(X); subplot(2,2,2); im(X1-X2);
      subplot(2,2,3); im(X1); subplot(2,2,4); im(X2);

     EXAMPLE - translation
      load trees;
      XT = imtransform2(X,0,1.5,'bicubic','crop');
      figure(1); clf; im(X,[0 128]); figure(2); clf; im(XT,[0 128]);

     See also TEXTUREMAP, INTERP2

     Piotr's Image&Video Toolbox      Version 2.03
     Copyright 2008 Piotr Dollar.  [pdollar-at-caltech.edu]
     Please email me if you find bugs, or have suggestions or questions!
     Licensed under the Lesser GPL [see external/lgpl.txt]

## CROSS-REFERENCE INFORMATION

This function calls:

- im Function for displaying grayscale images.
- arrayToDims Pads or crops I appropriately so that size(IC)==dims.
- rotationMatrix Performs different operations dealing with a rotation matrix

This function is called by:

- jitterImage Creates multiple, slightly jittered versions of an image.