PyEXR
A simple EXR IO-library for Python that simplifies the use of OpenEXR.
Installation
pip install pyexr
Reading
Simple files
import pyexr
with pyexr.open("color.exr") as file:
file.channels
file.width
file.height
file.channel_precision["R"]
img = file.get()
img = file.get(precision=pyexr.HALF)
red = file.get("R")
red = file.get("R", precision=pyexr.HALF)
Fat / Multi-channel EXRs
import pyexr
with pyexr.open("multi-channel.exr") as file:
file.channels
file.width
file.height
all = file.get()
var = file.get("Variance")
col = file.get("default")
file.channel_map['default']
var_r = file.channel("Variance.R")
One line reading
import pyexr
img = pyexr.read("color.exr")
img = pyexr.read("color.exr", precision=pyexr.HALF)
all = pyexr.read("multi-channel.exr")
col = pyexr.read("multi-channel.exr", "default")
var = pyexr.read("multi-channel.exr", "Variance")
col, var = pyexr.read("multi-channel.exr", ["default", "Variance"])
col, var = pyexr.read("multi-channel.exr", ["default", "Variance"], precision=pyexr.HALF)
col, var = pyexr.read("multi-channel.exr", ["default", "Variance"], precision=[pyexr.HALF, pyexr.FLOAT])
Writing
You can write a matrix to EXR without specifying channel names. Default channel names will then be used:
# columns | default |
---|
1 channel | Z |
2 channels | X, Y |
3 channels | R, G, B |
4 channels | R, G, B, A |
import pyexr
depth
color
normal
pyexr.write("out.exr", depth)
pyexr.write("out.exr", color)
pyexr.write("out.exr", normal,
channel_names=['X','Y','Z'])
Writing Fat EXRs
import pyexr
depth
color
variance
data = {'default': color, 'Depth': depth, 'Variance': variance}
pyexr.write("out.exr", data)
pyexr.write(
"out.exr",
data,
precision = {'default': pyexr.HALF},
channel_names = {'Depth': ['Q']}
)