-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrotation.m
56 lines (42 loc) · 1.35 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
function rotate( img, alpha )
[w, h, ~] = size(img);
%estremi = [1 1; 1 w; h 1; h w];
xEstremi = [1, w, 1, w];
yEstremi = [1, 1, h, h];
% ruoto i 4 estremi
estremiRuotati = ...
[rotationSys(xEstremi(1), yEstremi(1), alpha), ...
rotationSys(xEstremi(2), yEstremi(2), alpha), ...
rotationSys(xEstremi(3), yEstremi(3), alpha), ...
rotationSys(xEstremi(4), yEstremi(4), alpha)];
for i=1:4
xRotEstremi(i) = estremiRuotati(i,1);
yRotEstremi(i) = estremiRuotati(i,2);
end
% trovo il massimo e minimo delle ordinate
minY = min(yRotEstremi);
maxY = max(yRotEstremi);
% trovo il massimo e minimo delle ascisse
minx = min(xRotEstremi);
maxX = max(xRotEstremi);
% trovo le dimensioni della nuova immagine
% come la distanza tra i minimi e i massimi
H = pdist([minY, maxY]);
W = pdist([minX, maxX]);
new_img = zeros(H, W);
for Y = 1:H
for X=1:W
new_img(x-w/2, y-h/2) = ...
img(Y-H/2, X-W/2);
end
end
figure; imshow(new_img);
end
function [soly, solx] = rotationSys(x, y, alpha)
syms X Y
eqn1 = X * cos(alpha) - Y * sin(alpha) == x;
eqn2 = Y * cos(alpha) - X * sin(alpha) == y;
sol = solve([eqn1, eqn2], [X, Y]);
solx = sol.x;
soly = sol.y;
end