Return home

Affine Transformation Example

An affine transformation is a linear 2-D geometric transformation. It is performed by applying a linear combination of translationrotationscaling and shearing operations. The affine transformation preserves both straight lines and ratios of distances between points on the straight lines.

maketform

Syntax

http://www.mathworks.com/help/toolbox/images/ref/maketform.html

Code

None

Example(s)

close all;

clear all;

clc;

% Translation: tx   ty

tx = -5;

ty = -5;

T_t = [1   0   0; ...

       0   1   0; ...

       tx ty   1];

% Scaling: sx, sy

sx = 2;

sy = 2;

T_s = [sx  0    0; ...

        0   sy   0; ...

        0   0    1];

 

% Rotation: theta

theta = deg2rad(-3);

T_r = [ cos(theta)  -sin(theta)  0; ...

        sin(theta)   cos(theta)  0; ...

             0            0      1];

% Shearing : shx, shy 

shx=0.15;

shy=0.05;

T_sh = [   1   shx    0; ...

         shy     1    0; ...

         0       0    1];

 

T_affine = T_t*T_s*T_r*T_sh;

I = imread('cameraman.tif');

 

tform = maketform('affine', T_affine);

J = imtransform(I,tform );%, 'XData',[1 3*size(I,2)],'YData',[1 3*size(I,1)]);

imshow(I), figure, imshow(J)