diff --git a/README.md b/README.md index a89ba4c..c3a73a2 100644 --- a/README.md +++ b/README.md @@ -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) +``` diff --git a/exr_info/exr_info.py b/exr_info/exr_info.py index fc17454..cd9495f 100644 --- a/exr_info/exr_info.py +++ b/exr_info/exr_info.py @@ -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. @@ -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