-
Notifications
You must be signed in to change notification settings - Fork 3
/
rotation.m
36 lines (36 loc) · 1.07 KB
/
rotation.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
function rot = rotation(image,ang)
if size(image,3)==3
[l,c,h] = size(image);
diam = ceil(sqrt(l^2+c^2));
imRotationee = uint8(zeros(diam,diam,3));
for k=1:h
for i=1:diam
for j=1:diam
a = round((l/2) + (i-(diam/2))*cos(ang) - (j-(diam/2))*sin(ang));
b = round((c/2) + (j-(diam/2))*cos(ang) + (i-(diam/2))*sin(ang));
if ( a>0 && a<=l && b>0 && b<=c )
imRotationee(i,j,k)=image(a,b,k);
else
imRotationee(i,j,k)=0;
end
end
end
end
else
[l,c]=size(image);
diam = ceil(sqrt(l^2+c^2));
imRotationee = uint8(zeros(diam,diam));
for i=1:diam
for j=1:diam
a = round((l/2) + (i-(diam/2))*cos(ang) - (j-(diam/2))*sin(ang));
b = round((c/2) + (j-(diam/2))*cos(ang) + (i-(diam/2))*sin(ang));
if ( a>0 && a<=l && b>0 && b<=c )
imRotationee(i,j) = image(a,b);
else
imRotationee(i,j)=0;
end
end
end
end
rot = imRotationee;
end