forked from jianxiongxiao/ProfXkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimreadAutoRot.m
executable file
·40 lines (34 loc) · 1.12 KB
/
imreadAutoRot.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
function im = imreadAutoRot(filename)
% This is a replacement of imread in Matlab to handle auto-rotation in JPEG.
% Matlab seems not able to handle automatic rotation of image in imread
% (at least until R2012a version).
% Therefore, I wrote this file to automatically rotate the image into the
% write direction based on EXIF orientation.
% I have tested this function on iPhone 5 with iOS 6.
% Jianxiong Xiao
% Reference: JPEG image format at http://www.impulseadventure.com/photo/exif-orientation.html
im = imread(filename);
try
info = imfinfo(filename);
switch info.Orientation
case 1
case 2
im = im(:,end:-1:1,:);
case 3
im = imrotate(im,180);
im = im(:,end:-1:1,:);
case 4
im = im(:,end:-1:1,:);
case 6
im = imrotate(im,-90);
case 5
im = im(:,end:-1:1,:);
im = imrotate(im,-90);
case 8
im = imrotate(im,90);
case 7
im = imrotate(im,90);
im = im(:,end:-1:1,:);
end
catch
end