forked from marcusstenbeck/tnm034-qr
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrotation.asv
More file actions
64 lines (52 loc) · 2.05 KB
/
rotation.asv
File metadata and controls
64 lines (52 loc) · 2.05 KB
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
57
58
59
60
61
62
63
64
% A function that fixes the rotation of the image
% PARAMETERS
% IN:
% imin: The input image normalized between 0 and 1
% corner, right, bottom: coordinates for respective PIF
% OUT:
% imout: The resulting image, aligned to the axises
function [imout, new_corner, new_right, new_bottom] = rotation(imin)%, corner, right, bottom)
imin = imread(imin);
double_image = im2double(imin); % turning the pixel-values into double-values
normalized_image = double_image / max(double_image(:)); % normalizes between 0 and 1
normalized_image(normalized_image < 0.5) = 0;
normalized_image(normalized_image >= 0.5) = 1;
corner = [236 68]; %hörnet
right = [242 368]; %längst åt höger
bottom = [612 130]; %längst ned
%sätter ett högt värde så man kan hitta de senare
normalized_image(corner(1), corner(2)) = 127;
normalized_image(right(1), right(2)) = 128;
normalized_image(bottom(1), bottom(2)) = 129;
vector_corner_to_right = right - corner; %hörn till höger
vector_corner_to_bottom = bottom - corner; %hörn till ned
imshow(normalized_image)
hold on
plot(vector_corner_to_right, 'b')
plot(vector_corner_to_bottom, 'r')
magnitude_right = norm(vector_corner_to_right)
magnitude_bottom = norm(vector_corner_to_bottom)
if(magnitude_right > magnitude_bottom)
'right är störst'
end
hold off
vector_imaginary = [bottom(1), right(2)];
DP = dot(vector_corner_to_right, vector_imaginary);
magvector1 = norm(vector_corner_to_right);
magvector2 = norm(vector_imaginary);
radian = acos(DP/(magvector1*magvector2));
angle = radian*(180/pi)
if(bottom(1) < corner(1))
%B = imrotate(imin,90-angle);
else
%49 if bild4, 52 if bild2 from tnm034 else 53, 53 if bild3
B = imrotate(normalized_image,52-angle);
end
[nRowC, nColC] = find(B==127);
new_corner = [nRowC, nColC];
[nRowR, nColR] = find(B==128);
new_right = [nRowR, nColR];
[nRowB, nColB] = find(B==129);
new_bottom = [nRowB, nColB];
%imout=B;
return