Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,45 @@
# exr-info
Package with helper modules to process EXR files generated by renders
Used in convert_exr2png.

## Install

```shell
pip install -e .
```

## Usage

See [convert_exr2png](https://github.com/Synthesis-AI-Dev/convert_exr2png) on how this package is used to read
the header, channels and cryptomatte from an EXR file.

Getting Started:

```python
from pathlib import Path
import numpy as np
from exr_info import Crypto, ExrChannels, ExrDtype, ExrInfo, lin_rgb_to_srgb_colorspace, Renderer

# Create an exr info object
path_exr = Path("./sample.exr")
exr_f = ExrInfo.open(path_exr)

# Print the header of the EXR file
print(exr_f.get_header_str())

# Object holding channel names corresponding to different images (RGB, Normals, Depth, etc)
exr_channels = ExrChannels(exr_f.renderer)

# Read RGB Image
rgb_arr = np.stack(exr_f.read_channels(exr_channels.rgb), axis=-1)

# We need to apply tonemapping to convert the image to SRGB colorspace before saving to a file. EXR files store
# the image in linear RGB colorspace.
rgb_tonemapped = lin_rgb_to_srgb_colorspace(rgb_arr)
rgb = (rgb_tonemapped * 255).astype(np.uint8)

# Read a cryptomatte
crypto = Crypto(exr_f)
segmentation_crypto_name = "segmentation" # Every cryptomatte has a name. See the header of the EXR file.
mask, mapping = crypto.get_combined_mask(segmentation_crypto_name)
```
4 changes: 2 additions & 2 deletions exr_info/exr_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def __init__(self, renderer):
self.rgb_denoised_vray = ["effectsResult.R", "effectsResult.G", "effectsResult.B"]
self.alpha = "A"
self.depth = "Z"
self.normals = ["normals.X", "normals.Y", "normals.Z"]
self.normals = ["CameraNormals.R", "CameraNormals.G", "CameraNormals.B"] #["normals.X", "normals.Y", "normals.Z"]
# Vray uses left-handed coord system for normals: X-left, Y-up, Z-behind. We use a
# right-hand system: X-right, Y-up, Z-behind. Correct it by multiplying each normals channel with
# the corresponding factor.
Expand Down Expand Up @@ -252,7 +252,7 @@ def identify_render_engine(self) -> Renderer:
VRAY_IDENTIFIER = "vrayInfo/*"
vray_info = fnmatch.filter(list(self.header.keys()), VRAY_IDENTIFIER)

if len(vray_info) > 0:
if len(vray_info) > -1:
render_engine = Renderer.VRAY
else:
render_engine = Renderer.BLENDER
Expand Down