# templateAffineTransform

## PURPOSE

templateAffineTranform - Affine transform of vertices in the template.

## SYNOPSIS

function [outRow, outCol, outO, outS] =templateAffineTransform(tScale, rScale,cScale,rotation,inRow,inCol,inO,inS,nOri)

## DESCRIPTION

     templateAffineTranform - Affine transform of vertices in the template.

     tScale: change of log-scale for the whole template
     rScale: change of log-scale for row index (small change)
     cScale: change of log-scale for column index (small change)
     rotation: rotation of template
     inX, inY, inO, inS: selected position (relative to the origin), orientation and scale of elements
     nOri: number of quantized orientations inside 0 ~ pi

## CROSS-REFERENCE INFORMATION

This function calls:

This function is called by:

- generateTransformedS2Templates generateTransformedS2Templates - Affine transforms of the S2
- generateTransformedTemplates generateTransformedTemplates - Affine transforms of the ellipsoid

## SOURCE CODE

    0001 function [outRow, outCol, outO, outS] =...
    0002     templateAffineTransform(tScale, rScale,cScale,rotation,inRow,inCol,inO,inS,nOri)
    0003 % templateAffineTranform - Affine transform of vertices in the template.
    0004 %
    0005 % tScale: change of log-scale for the whole template
    0006 % rScale: change of log-scale for row index (small change)
    0007 % cScale: change of log-scale for column index (small change)
    0008 % rotation: rotation of template
    0009 % inX, inY, inO, inS: selected position (relative to the origin), orientation and scale of elements
    0010 % nOri: number of quantized orientations inside 0 ~ pi
    0011
    0012 A1 = eye(3); A1(1,1) = cScale * (2^(tScale/2)); A1(2,2) = rScale * (2^(tScale/2));
    0013 angle = rotation * pi/nOri;
    0014 A2 = eye(3); A2(1,1) = cos(angle); A2(1,2) = sin(angle); A2(2,1) = -A2(1,2); A2(2,2) = A2(1,1);
    0015 outRow = zeros(length(inRow),1);
    0016 outCol = zeros(length(inCol),1);
    0017 outO = zeros(length(inO),1);
    0018 outS = zeros(length(inS),1);
    0019
    0020 for iF = 1:length(inRow)
    0021     pt = [inCol(iF), -inRow(iF), 1] * A1;
    0022     pt = pt * A2;
    0023
    0024     outCol(iF) = floor( .5 + pt(1) );
    0025     outRow(iF) = floor( .5 - pt(2) );
    0026     outO(iF) = inO(iF) + rotation;
    0027     outS(iF) = inS(iF) + tScale;
    0028     while outO(iF) < 0
    0029         outO(iF) = outO(iF) + nOri;
    0030     end
    0031     while outO(iF) >= nOri
    0032         outO(iF) = outO(iF) - nOri;
    0033     end
    0034 end
    0035
    0036
    0037 % note: during squeezing, the orientations of some elements are changed. But
    0038 %    we assume the squeezing effect is negligible on filter orientations.
    0039
    0040 % Because of scaling, some Gabors are not applicable.
    0041 % But we still keep all Gabor elements, and will filter out these elements when
    0042 % computing S2 scores.
    0043