2013年3月2日 星期六

JPEG Rotation and EXIF Orientation / EXIF - image metadata / IrfanView - lossless JPG operations


JPEG Rotation and EXIF Orientation

Digital Cameras with Orientation Sensors

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

Many newer digital cameras (both dSLR and Point & Shoot digicams) have a built-in orientation sensor. Virtually allCanon 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).



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.

For the following discussion, it may be helpful to understand the concepts behind lossless rotation.

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:
1
Top
Left side
2*
Top
Right side
3
Bottom
Right side
4*
Bottom
Left side
5*
Left side
Top
6
Right side
Top
7*
Right side
Bottom
8
Left side
Bottom

NOTE: Values with "*" are uncommon since they represent "flipped" orientations.


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 Photo Viewer (Windows 7)
No
Windows Picture and Fax Viewer (Windows XP)
No
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) and Windows Photo Viewer (built into Windows 7) do 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.

Beware of Rotating Photos in Windows Picture / Photo 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/reset, if you do a rotation followed by its reverse rotation on a portrait photo (eg. rotate clockwise, then rotate counter-clockwise), the resulting orientation observed by other viewers such as Photoshop will be wrong!

In fact, when you use the rotate functions of Windows Picutre Viewer, 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:

Removed
Added
Modified
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



Note that, in general, most image editors (such as Photoshop, Lightroom and many others) do not rotate images losslessly. This is made obvious by the fact that the Save function provides compression quality options (eg. 1-12, High, Low, etc.) and is therefore applying [lossy] JPEG recompression to your image content.

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.



========================================================================



Exchangeable image file format (EXIF)

維基百科,自由的百科全書

可交換圖像文件常被簡稱為EXIFExchangeable image file format),是專門為數位相機的照片設定的,可以記錄數位照片的屬性信息和拍攝數據。
EXIF最初由日本電子工業發展協會1996年制定,版本為1.0。1998年,升級到2.1,增加了對音頻文件的支持。2002年3月,發表了2.2版。
EXIF可以附加於JPEGTIFFRIFF等文件之中,為其增加有關數位相機拍攝信息的內容和索引圖或圖像處理軟體的版本信息。
Windows 7作業系統為例,最簡單的查看EXIF信息的方法是右鍵點擊圖片打開菜單,點擊屬性並切換到詳細信息標籤下即可。
EXIF信息是可以被任意編輯的,因此只有參考的功能。
EXIF信息以0xFFE1作為開頭標記,後兩個位元組表示EXIF信息的長度。所以EXIF信息最大為64 kB,而內部採用TIFF格式。

範例

以下表列幾項EXIF會提供的訊息:

Tag
項目
Value
Manufacturer
製造廠商
CASIO
Model
相機型號
QV-4000
Orientation (rotation)
影像方向
top - left [8 possible values[19]]
Software
Software
Ver1.01
Date and Time
最後異動時間
2003:08:11 16:45:32
YCbCr Positioning
YCbCrPositioning
centered
Compression

JPEG compression
x-Resolution
影像解析度 X
72.00
y-Resolution
影像解析度 Y
72.00
Resolution Unit
解析度單位
Inch
Exposure Time
曝光時間
1/659 sec.
FNumber
光圈
f/4.0
ExposureProgram
拍攝模式
Normal program
Exif Version
EXIF 資訊版本
Exif Version 2.1
Date and Time (original)
影像拍攝時間
2003:08:11 16:45:32
Date and Time (digitized)
影像存入時間
2003:08:11 16:45:32
ComponentsConfiguration

Y Cb Cr -
Compressed Bits per Pixel

4.01
ISO speed ratings
ISO 感光值
ISO 100
Exposure Bias

0.0
MaxApertureValue
曝光補償(EV+-
2.00
Metering Mode
測光模式
Pattern
Flash
Flash did not fire.
Focal Length
鏡頭實體焦長
20.1 mm
MakerNote

432 bytes unknown data
FlashPixVersion
Flashpix 版本
FlashPix Version 1.0
Color Space
影像色域空間
sRGB
PixelXDimension
影像尺寸 X
2240
PixelYDimension
影像尺寸 Y
1680
File Source

DSC
InteroperabilityIndex

R98
InteroperabilityVersion

(null)



========================================================================



IrfanView
維基百科,自由的百科全書

IrfanViewMicrosoft Windows系統下的一款圖片檢視器,基本功能包括圖像瀏覽、圖片的簡單編輯、圖片的格式轉換等。非商業使用是免費的,而商業使用則需要進行付費註冊。
該軟件的作者是畢業於奧地利維也納大學的Irfan Skiljan。

功能特性

該軟件佔用的空間非常小,基本安裝只佔用1.6 MB,而完整安裝所有外掛模組另需10 MB左右的空間。
影像瀏覽時,具有多種適應窗口的方式,以及幻燈片播放的選項,也能夠進行有縮圖瀏覽。瀏覽影像時反應迅速,但對於部分語系的作業系統的支援有所欠缺,在部分非英文資料夾的圖片瀏覽時選擇下一張圖片時會產生錯誤。
支援多種圖片格式及少量影片格式、音樂格式以及文字格式。能夠進行圖片格式轉換並具有批次轉換及重新命名功能。
能夠進行一定的影像編輯操作,能夠進行圖片的顏色調整,旋轉,修剪,調整大小等,同樣也能進行批次操作。
具有屏保及幻燈片功能,也能夠製作帶MP3的螢幕保護程式,在沒有安裝Irfanview的機器上使用。
該軟件設有超過32種語言以供選擇,包括簡繁中文(需要另行下載需要的語言檔案,並不包含於安裝包)。

外部連結



本頁面最後修訂於2012年8月16日 (星期四) 15:14。



========================================================================