forked from AbdoKamel/simple-camera-pipeline
-
Notifications
You must be signed in to change notification settings - Fork 1
/
FixOrientation.m
37 lines (33 loc) · 1.12 KB
/
FixOrientation.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 [fixedImage] = FixOrientation(image, metadata)
%FIXORIENTATION Fix the image's orientation
% 0x0112 Orientation int16u IFD0
% 1 = Horizontal (normal)
% 2 = Mirror horizontal
% 3 = Rotate 180 CW
% 4 = Mirror vertical
% 5 = Mirror horizontal and rotate 270 CW
% 6 = Rotate 90 CW
% 7 = Mirror horizontal and rotate 90 CW
% 8 = Rotate 270 CW
fixedImage = image;
if isfield(metadata, 'Orientation')
switch metadata.Orientation
case 2
fixedImage = flip(image, 2);
case 3
fixedImage = imrotate(image, -180);
case 4
fixedImage = flip(image, 1);
case 5
fixedImage = flip(image, 2);
fixedImage = imrotate(fixedImage, -270);
case 6
fixedImage = imrotate(image, -90);
case 7
fixedImage = flip(image, 2);
fixedImage = imrotate(fixedImage, -90);
case 8
fixedImage = imrotate(image, -270);
end
end
end