Why is matlab reading some images in rotated by 90 degrees?

80 ビュー (過去 30 日間)
Thomas Bloomfield
Thomas Bloomfield 2018 年 4 月 4 日
回答済み: DGM 2023 年 1 月 5 日
I am reading in many portrait images for a face recognition project.
However Matlab is reading some images into the workspace rotated by 90 degrees, while others have the correct orientation (i.e. the orientation seen in the directory they are stored in).
The only obvious discriminating factor is the sub-folder the images come from, e.g. subfolders 1-45 are OK, but images within subfolders 46-50 are being read in incorrectly.
The method being used is as follows:
I = imread('..\046\IMG_0242.jpg');
imshow(I)
  3 件のコメント
Guillaume
Guillaume 2018 年 4 月 4 日
It's either a bug in your code or the files are stored rotated 90 degrees.
It is extremely unlikely that it is a bug in matlab. Someone would have noticed by now if imread did not read images properly.
So... show us your code.
Also, what format are the images stored as?
Guillaume
Guillaume 2018 年 4 月 4 日
Can you actually show the whole output of imfinfo for a correct and rotated image?
Note that some jpeg images may also have EXIF metadata. One possible EXIF tag is an orientation tag that says how the image should be rotated after it's been read.

サインインしてコメントする。

回答 (1 件)

DGM
DGM 2023 年 1 月 5 日
If you're loading photographs from a digital camera (which is what that looks like), this is a likely outcome. Imread() does not check the Orientation tag in EXIF metadata, so if your camera was rotated during the shot, the image won't be reoriented as it will in other software.
See these threads.
Attached is a reduced-compatibility version of one of the tools from MIMT. The version in MIMT has broader version support and doesn't require IPT, but it relies on MIMT, so it won't run here on the forum.
Imreadort() is a simple wrapper for imread() that attempts to catch any cases where Orientation metadata is present. If orientation info is present and understandable, it will rectify the image.
inpict = imread('Landscape_5.jpg'); % read it with imread()
imshow(inpict)
inpict = imreadort('Landscape_5.jpg'); % read it with imreadort() instead
imshow(inpict)

カテゴリ

Help Center および File ExchangeCamera Calibration についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by