-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
129 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -152,4 +152,5 @@ dmypy.json | |
# Cython debug symbols | ||
cython_debug/ | ||
|
||
example_exr* | ||
.vscode/settings.json | ||
example_exr* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"terminal.integrated.env.linux": { | ||
"PYTHONPATH": "${workspaceFolder}:${env:PYTHONPATH}" | ||
}, | ||
"terminal.integrated.env.osx": { | ||
"PYTHONPATH": "${workspaceFolder}:${env:PYTHONPATH}" | ||
}, | ||
"terminal.integrated.env.windows": { | ||
"PYTHONPATH": "${workspaceFolder};${env:PYTHONPATH}", | ||
"OCIO": "${workspaceFolder}/config.ocio" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import numpy as np | ||
import OpenEXR | ||
import Imath | ||
|
||
def read_exr(image_path: str) -> np.ndarray: | ||
"""Read an EXR image from file and return it as a NumPy array. | ||
Args: | ||
image_path (str): The path to the EXR image file. | ||
Returns: | ||
np.ndarray: The image data as a NumPy array. | ||
""" | ||
# Open the EXR file for reading | ||
exr_file = OpenEXR.InputFile(image_path) | ||
|
||
# Get the image header | ||
header = exr_file.header() | ||
|
||
# Get the data window (bounding box) of the image | ||
data_window = header['dataWindow'] | ||
|
||
# Get the channels present in the image | ||
channels = header['channels'] | ||
|
||
# Calculate the width and height of the image | ||
width = data_window.max.x - data_window.min.x + 1 | ||
height = data_window.max.y - data_window.min.y + 1 | ||
|
||
# Determine the channel keys | ||
channel_keys = 'RGB' if len(channels.keys()) == 3 else channels.keys() | ||
|
||
# Read all channels at once | ||
channel_data = exr_file.channels(channel_keys, Imath.PixelType(Imath.PixelType.FLOAT)) | ||
|
||
# Create an empty NumPy array to store the image data | ||
image_data = np.zeros((height, width, len(channel_keys)), dtype=np.float32) | ||
|
||
# Populate the image data array | ||
for i, data in enumerate(channel_data): | ||
# Retrieve the pixel values for the channel | ||
pixels = np.frombuffer(data, dtype=np.float32) | ||
# Reshape the pixel values to match the image dimensions and store them in the image data array | ||
image_data[:, :, i] = pixels.reshape((height, width)) | ||
|
||
return image_data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters