OpenEXR bindings for Python

Download OpenEXR-1.2.0.tar.gz.

OpenEXR is an image format developed by ILM. OpenEXR's main advantage over other image formats is high dynamic range: it supports floating point pixels. High dynamic range (HDR) images allow a closer representation of real-world colors: shadow and highlight detail is preserved.

Full documentation is online and as a PDF.

Here is a brief sample that duplicates exrnormalize from exrtools

import sys
import array
import OpenEXR
import Imath

if len(sys.argv) != 3:
    print "usage: exr-input-file exr-output-file"

# Open the input file
file = OpenEXR.InputFile(sys.argv[1])

# Compute the size
dw = file.header()['dataWindow']
sz = (dw.max.x - dw.min.x + 1, dw.max.y - dw.min.y + 1)

# Read the three color channels as 32-bit floats
FLOAT = Imath.PixelType(Imath.PixelType.FLOAT)
(R,G,B) = [array.array('f',, FLOAT)).tolist() for Chan in ("R", "G", "B") ]

# Normalize so that brightest sample is 1
brightest = max(R + G + B)
R = [ i / brightest for i in R ]
G = [ i / brightest for i in G ]
B = [ i / brightest for i in B ]

# Convert to strings
(Rs, Gs, Bs) = [ array.array('f', Chan).tostring() for Chan in (R, G, B) ]

# Write the three color channels to the output file
out = OpenEXR.OutputFile(sys.argv[2], OpenEXR.Header(sz[0], sz[1]))
out.writePixels({'R' : Rs, 'G' : Gs, 'B' : Gs })


Prerequisite is Python 2.5 and up, and the OpenEXR C++ library.

Then to install the Python bindings themselves:

easy_install -U openexr

or you can download the above source directory then do:

sudo python install

Change log

OpenEXR-1.2 (Aug 2010)








Not Yet Implemented

I have yet to implement various OpenEXR features - so if you want something in particular, email me and I will try to get it done.