Return to Digital Photography Articles

JPEG Rotation and EXIF Orientation

Digital Cameras with orientation sensors allow auto-rotation of portrait images. Unfortunately, support for this feature is not widespread or consistently applied.

Digital Cameras with Orientation Sensors

Many newer digital cameras (both dSLR and Point & Shoot digicams) have a built-in orientation sensor. Virtually all Canon and Nikon digital cameras have an orientation sensor. The output of this sensor is used to set the EXIF orientation flag in the image file's metatdata to reflect the positioning of the camera with respect to the ground. Canon calls their sensor the "Intelligent Orientation" sensor. It is presumably a 2-axis tilt sensor, allowing 4 possible orientations to be detected (shown in the left side of the diagram below).

EXIF Orientation Flag Values

 

Note that one would only expect the four orientation settings shown on the left to be possible with a digital camera. The other four settings would imply that the resulting image was flipped horizontally before recording. Unless the camera were to encode the image right-to-left or know that you were taking a photo in a mirror, I don't see how these values will ever be used.

The values 1-8 represent the following descriptions (as shown by utilities that support EXIF field decode):

EXIF Orientation Value Row #0 is: Column #0 is:
1TopLeft side
2TopLeft side
3BottomRight side
4BottomRight side
5Left sideTop
6Right sideTop
7Right sideBottom
8Left sideBottom

Auto-rotation in Digital Cameras

While your digital camera may include an option to "auto-rotate images" due to the camera's orientation, this is almost always just a "virtual rotation". A flag is set to indicate to the viewing software / LCD preview which way to rotate the image before display, rather than rotating the image content itself.

As lossless image rotation is a fairly compute-intensive operation, digital cameras are not likely to include true lossless rotation after capturing the photo. The CCD/CMOS sensor hardware is designed to stream raw data in a particular direction (e.g. rows then columns), and so it may be hard to incorporate true auto-rotation in-camera without a performance impact to continuous shooting (frames per second).

Software Support for Orientation

While there are countless software programs available today that display JPEG images, only a subset of them actually interpret the EXIF Orientation flag. Just like color management, many programs simply display the JPEG image as it is stored, and completely ignore any extra details stored in the file's metadata. The most important of these additional details is the Orientation flag, stored in the JPEG APP1 marker under EXIF IFD0.

Application Orientation Supported?
Windows Picture and Fax ViewerNo
IrfanView Yes (need to enable)
Photoshop Yes

IrfanView Auto-rotation

In IrfanView, auto-rotation is not enabled by default. To ensure that images are auto-rotated, you will find the option located under Options->Properties in the JPG/PCD/GIF tab.

Windows Picture and Fax Viewer

Surprisingly, the Windows Picture and Fax Viewer (built into Windows XP) does not support the EXIF orientation flag. This is surprising, as the makers have obviously thought enough to support lossless rotation functions. So, what you will see shown by the viewer is the real image data (assuming landscape orientation), without respecting any indication from the camera as to the real orientation of the image.

Do not Rotate Photos in Windows Picture and Fax Viewer!

Another surprising detail is that if you decide to perform lossless image rotation (by using the Rotate Clockwise or Rotate CounterClockwise buttons), the EXIF Orientation flag is removed! As the flag is removed, if you do a double-rotation on a portrait photo (rotate, then rotate in the opposite direction), the resulting orientation observed by other viewers such as Photoshop will be wrong!

In fact, when you use the rotate functions of this utility, most of the image metadata (camera information, shot details, makernotes, etc.) are deleted. Therefore, I strongly recommend against using this program to rotate any of your digital photos.

I have also noticed that some images which were rotated that don't conform to 16x16 pixel multiples, the quantization tables don't appear to be rotated properly.

Because many new digital photographers may not be aware of this, Nikon even went so far as to issue a press release to warn of the potential dangers.

  • NOTE: The damage is done as soon as you press one of the rotate buttons . The disk icon is just for copying the file and should not be thought of as a Save button!

The following table details some of the metadata corrupted / modified by Windows Picture and Fax Viewer:

RemovedAddedModified
IFD0-Orientation IFD0-x1001
IFD0-x1002
IFD0-xA401
IFD0-xA402
IFD0-xA403
 
SubIFD-ExifInteroperabilityOffset
SubIFD-CustomRendered
SubIFD-ExposureMode
SubIFD-WhiteBalance
SubIFD-SceneCaptureType
  SubIFD-MakerNote
SubIFD-UserComment
MakerNotes: Nearly all fields zeroed
out except: SerialNumber, ImageNumber
   

 

Auto-Rotation Utilities

There are several tools that allow the image content to be rotated losslessly in software, based on the information stored in the EXIF orientation flag. By far the best time to perform this is during image import (e.g. from memory card). Most import applications (such as DownloaderPro) can do this during the copy operation (from memory card to hard drive). Doing so ensure that all programs can see the image properly rotated, without having to rely on the EXIF Orientation flag. This means that even programs such as Microsoft's Windows Picture and Fax Viewer will also show correct orientation for portrait / vertical images.

Most programs will rotate the image content and then update the Orientation flag to reflect the new orientation (usually a value of 1), while still leaving other metadata intact.

 


Reader's Comments:

Please leave your comments or suggestions below!
2008-01-22Davide Bolsi
 "Unless the camera were to encode the image right-to-left or know that you were taking a photo in a mirror, I don't see how these values will ever be used."

I agree, these values can be used for example with telescopes (or other optical devices) with a mirror diagonal on the optical path... but you will have to (be able to) properly set the camera in order to get the correct value.
In my opinion these values are aimed to different imaging devices like xray machines, slide scanners, etc
 Great point Davide!
2008-01-08Max
 Hi

Thanks a lot for the article, first !
Then i just would have like to know if the small soft given 2 posts below is a good solution in my case :

I'm usually using XnView to rotate my pictures.
However i recently got some taken by a Canon camera, meaning that the orientation exif flag is used. Thus XnView automatically rotates the pictures according to the flag, whereas Windows does not. But i would like to see the rotated pics in windows as well.
Thus i used the softawre advised (http://www.pilpi.net/software/JPEG-EXIF_autorotate.php) but i am not really certin of it to be the best solution :-)

Thanks for your advice !
 I have not used that particular tool myself, as I rely on DownloaderPro instead to do this function (plus the renaming and folder organization). I definitely think you can trust Downloader Pro as it has been widely used and well thought-out.
2007-08-31Tibor
 "While your digital camera may include an option to "auto-rotate images" due to the camera's orientation, this is ONLY used for the purposes of the LCD display on-camera."
My Kodak DX7440 does rotate the image, not only on its LCD display, but the file itself, the image is already rotated when I copy to PC.
 Definitely... I'm not sure why I wrote it as being only a LCD display function as that is not what I had intended to write -- the auto-rotate function is almost always just a "virtual rotation", not a real rotation of image content. Thanks for pointing it out -- I've clarified the sentence now.
2007-08-17RayZ
 Thanks for the article. I found that this small tool does the trick for the photos from my 300d. Cheers, Ray.

http://www.pilpi.net/software/JPEG-EXIF_autorotate.php
 
2007-03-06Ian
 Hi,

Thanks very much for the details in your very helpful article. I am developing some software that is to include auto-rotation based upon the EXIF information, but I want to try and get an idea of what proportion of cameras on the market have orientation sensors. Do you know of any lists anywhere? dpreview.com allows searching for cameras that have sensors but limits results to 10, and so it's hard to get an overall picture of what support there is.

Thanks for any help you can provide.
 At first I thought that I might be able to automatically process photos from ~ 200 digicams (using JPEGsnoop) and see which ones omitted the EXIF Orientation flag. However, it quickly became apparent that even digicams without orientation sensors often still set the orientation bit (to the default 1). There were some exceptions, such as the Nikon D1 series, Nikon D100, Pentax *ist D, Sony DSC-F717, which don't include any JPEG Orientation flag in the file.

Generally speaking, I'm not aware of the proportion of models that include orientation sensors (or a list that would be easy to extract this from), but it is clear that it is quite prevalent in recent models, even in the cheaper lines.
2006-12-22Mark Worthington
 Regarding cropping, interesting advice … my "easy way out" is to use an application that performs lossless cropping .. I use BetterJPEG (which I've seen you mention elsewhere). Would you say that your restrictions are met using that app?

Cheers,
Mark
 Absolutely. When cropping in this programs that were designed with lossless operations in mind (some parts of IrfanView, BetterJPEG, jpegtran, etc.), there is almost always a restriction that would prevent you from cropping across a partial MCU (thereby making the crop no longer lossless).
2006-12-22Mark Worthington
 I meant to ask, what do you mean by "on properly sized images". Presumably this would apply to any of the available images-formats on a Canon camera .... ?

Cheers,
Mark
 By properly-sized I am referring to an image whose dimensions are a multiple of 8 pixels in both directions. Thankfully, Canon has never produced a digicam with partial MCU image dimensions, unlike some other manufacturers. Note that if you crop the image, you should keep these restrictions in mind (and better to use multiples of 16 pixels in both directions, to account for potential chroma subsampling).
2006-12-20Mark Worthington
 Thanks for the info. At last, something I can trust!!
Mark
 No problem!
2006-12-19Mark Worthington
 I agree that the best time to perform this auto-rotation is during image import (e.g. from memory card). Given that you mention Canon by name, their software, ZoomBrowser Ex, does enable this during import. However, from what I can gather it would appear that this is NOT a lossless process, and so I import with no rotation and apply the auto-rotation later on. I wondered if you could add any light on the ZoomBrowser "lossless" or not rotate?

Whatever is the consensus view of this software, it does offer some things that are otherwise hard to find, like viewing MakerNote information..

Regards,

Mark
 I have now tested Canon ZoomBrowser EX 5.7 and confirmed that it does use lossless rotation (on properly sized images) when you set the Rotate Actual Images checkbox. Unfortunately, it seems that there is a lot of misinformation about this on the net. It would help if Canon would advertise this fact in their documentation somewhere.

 


Leave a comment or suggestion for this page:

(Never Shown - Optional, if you want a reply)
 

NOTE: I am out of the country for several months (in India), so comments will be held and only posted infrequently. Thanks!

13 users online