OpenEXR bindings for Python

Download OpenEXR-1.0.tar.gz

OpenEXR is an image format developed by ILM. Its main advantage is higher dynamic range: it supports floating point pixels.

Full documentation is online and as a PDF.

Here's a brief sample that duplicates exrnormalize from exrtools.

import sys
import array
import OpenEXR
import Imath

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

# 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', file.channel(Chan, 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 the OpenEXR library. For a Debian-based Linux:

  sudo apt-get install libopenexr-dev
on MacOS with DarwinPorts do:
  sudo port install openexr
on BSD do:
  cd /usr/ports/graphics/OpenEXR
  sudo make install

Change log

OpenEXR-1.0.0

OpenEXR-0.0.4

OpenEXR-0.0.3

OpenEXR-0.0.1

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.