Radiance HDR (.pic, .hdr) file format

Written by Paul Bourke
May 2003


The original Radiance picture format (typically ".pic") is the basis for one of the standard HDR (High Dynamic Range image) image formats (".hdr"), supported by most HDR image editors including Adobe PhotoShop (eg: PhotoShop CS2, 2006). Each pixel is stored as 4 bytes, one byte mantissa for each r,g,b and a shared one byte exponent. The pixel data may be stored uncompressed or using a straightforward run length encoding scheme.

A Radiance image file consists of three sections: a header, resolution string, followed by the pixel data.

Header

The first bytes in a legal image file are "#?RADIANCE". This identifies the file as a likely image. Following this are a number of informative lines and assignments. For example it is traditional to include (and maintain) the series of programs/commands that generated the image, each appears on a separate line and a blank line indicates the end of the header. Some of the standard radiance based keywords/assignments are listed below.

  • Format

    Must be either "32- bit_rle_rgbe" or "32-bit_rle_xyze".

  • Exposure

    Followed by an exposure value.

  • Colorcorr

    Colour correction scaling for each r,g,b.

  • Software

    Software versions.

  • Pixaspect

    Ratio of the height to width of the pixel. If missing, assume 1.

  • View

    Radiance specific camera attributes.

  • Primaries

    The CIE (x,y) chromaticity coordinates of the three (RGB) primaries and the white point.

Resolution

The single resolution line consists of 4 values, a X and Y label each followed by a numerical integer value. The X and Y are immediately preceded by a sign which can be used to indicate flipping, the order of the X and Y indicate rotation. The standard coordinate system for Radiance images would have the following resolution string -Y N +X N. This indicates that the vertical axis runs down the file and the X axis is to the right (imagining the image as a rectangular block of data). A -X would indicate a horizontal flip of the image. A +Y would indicate a vertical flip. If the X value appears before the Y value then that indicates that the image is stored in column order rather than row order, that is, it is rotated by 90 degrees. The reader can convince themselves that the 8 combinations cover all the possible image orientations and rotations.

Pixel data

There are three formats the pixel data may appear in, they are: uncompressed, a standard run length encoding where a colour with 255 for all three mantissas indicates a run of the last pixel value (exponent is the run count), and an adaptive run length encoding. For the details of this the reader should consult the Radiance source code as the definitive reference.