Monday, August 2, 2010

Image Rotation

clear all; close all; clc;
f = imread('cameraman.tif');
[m n]=size(f);
f1 = padarray(f,[128 128]);
[m1 n1]=size(f1);
f2 = zeros(m1,n1);
figure,imshow(f1);
t=30; % Rotation angle
t1 = t*pi/180;
% rotate = maketform('affine',[ cos(t1)  sin(t1)  0; ...
%                                -sin(t1)  cos(t1)  0; ...
%                                     0       0       1 ]);

for i=1+128:m+128
for j=1+128:n+128

xd = fix((i*cos(t))+(i*sin(t)));
yd = fix((j*-sin(t))+(j*cos(t)));
a(i,j)=xd;
a1(i,j)=yd;

%f2(xd,yd)=f1(i,j);
end
end
ma1 = max(max(a));
mi1 = min(min(a));
mi1 = abs(mi1);
for i=1+128:m+128
for j=1+128:n+128
s1 = (mi1+a(i,j))+1;
s2 = a1(i,j);
f2(s1,s2)=f1(i,j);
end
end
figure,imshow(f2);

No comments: