Skip to main content

One line EXR manipulation library

Project description

Python compat PyPI codecov

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               # [R, G, B]
    file.width                  # 1280
    file.height                 # 720
    file.channel_precision["R"] # pyexr.FLOAT

    img = file.get()                         # (720,1280,3) np.float32 array
    img = file.get(precision=pyexr.HALF)          # (720,1280,3) np.float16 array
    red = file.get("R")                  # (720,1280,1) np.float32 array
    red = file.get("R", precision=pyexr.HALF) # (720,1280,1) np.float16 array

Fat / Multi-channel EXRs

import pyexr

with pyexr.open("multi-channel.exr") as file:
    file.channels               # [R, G, B, A, Variance.R, Variance.G, Variance.B]
    file.width                  # 1280
    file.height                 # 720

    all = file.get()            # (720,1280,7) np.float32 array (R,G,B,A,Var..)
    var = file.get("Variance")  # (720,1280,3) np.float32 array
    col = file.get("default")   # (720,1280,4) np.float32 array (R,G,B,A)
    file.channel_map['default'] # ['R','G','B','A']

    var_r = file.channel("Variance.R") # (720,1280,3) np.float32 array

One line reading

import pyexr

# 'color.exr' contains R, G, B
img = pyexr.read("color.exr")                  # (720,1280,3) np.float32 array
img = pyexr.read("color.exr", precision=pyexr.HALF) # (720,1280,3) np.float16 array

# 'multi-channel.exr' contains R, G, B, A, Variance.R, Variance.G, Variance.B
all = pyexr.read("multi-channel.exr")             # (720,1280,7) np array
col = pyexr.read("multi-channel.exr", "default")  # (720,1280,4) np array
var = pyexr.read("multi-channel.exr", "Variance") # (720,1280,3) np array

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  # (720,1280) np.float16 array
color  # (720,180,3) np.float32 array
normal # (720,180,3) np.float32 array

pyexr.write("out.exr", depth)            # one FLOAT channel: Z
pyexr.write("out.exr", color)            # three FLOAT channels: R, G, B
pyexr.write("out.exr", normal,
          channel_names=['X','Y','Z']) # three FLOAT channels: X, Y, Z

Writing Fat EXRs

import pyexr

depth    # (720,1280) np.float16 array
color    # (720,180,3) np.float32 array
variance # (720,180,3) np.float32 array

data = {'default': color, 'Depth': depth, 'Variance': variance} # default is a reserved name

pyexr.write("out.exr", data) # channels R, G, B, Depth.Z, Variance.(R,G,B)

# Full customization:
pyexr.write(
    "out.exr",
    data,
    precision = {'default': pyexr.HALF},
    channel_names = {'Depth': ['Q']}
) # channels R, G, B, Depth.Q, Variance.R, Variance.G, Variance.B

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyexr-0.4.0.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

pyexr-0.4.0-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file pyexr-0.4.0.tar.gz.

File metadata

  • Download URL: pyexr-0.4.0.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.12.2 Linux/6.5.0-1016-azure

File hashes

Hashes for pyexr-0.4.0.tar.gz
Algorithm Hash digest
SHA256 c8e222439af5622c24f322fea548e051654796e152dcc9666ccbd1627822d126
MD5 6a9ee4e0730972752d68bfc644d4cfbd
BLAKE2b-256 b766c56bb5ce2f4770af421055ddad98d870cfdb938b66a7194f7e6295d8b846

See more details on using hashes here.

File details

Details for the file pyexr-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: pyexr-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 6.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.12.2 Linux/6.5.0-1016-azure

File hashes

Hashes for pyexr-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e3d8e2a6e9435638ac42bbbe590572eb5956e314b86ca33cd3f79f45ab5ab156
MD5 b22cf3d11d52ae6f1249fa74a6016062
BLAKE2b-256 a1534e84c4b5e98cd142139076c4869d59835273a829bb9a9e2dbc43af028ae1

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page