Skip to content

Instantly share code, notes, and snippets.

@pjessesco
Created July 15, 2020 04:22
Show Gist options
  • Save pjessesco/3fe95d18a29b3320afef06749d76fc89 to your computer and use it in GitHub Desktop.
Save pjessesco/3fe95d18a29b3320afef06749d76fc89 to your computer and use it in GitHub Desktop.
import pyexr
import numpy as np
if __name__ == '__main__':
shift_coords = [[]]
path = "path_to_exr.exr"
img = pyexr.read(path)
height = img.shape[0]
width = img.shape[1]
r = pyexr.read(path, "R")
g = pyexr.read(path, "G")
b = pyexr.read(path, "B")
a = pyexr.read(path, "A")
new_r = np.zeros((height, width, 1))
new_g = np.zeros((height, width, 1))
new_b = np.zeros((height, width, 1))
new_a = np.zeros((height, width, 1))
print(width, height)
for h in range(height):
for w in range(width):
target_w = w+1
target_h = h
if target_w < width and target_w >= 0 and target_h < height and target_h >= 0:
new_r[target_h, target_w] = r[h][w]
new_g[target_h, target_w] = g[h][w]
new_b[target_h, target_w] = b[h][w]
new_a[target_h, target_w] = a[h][w]
color = np.concatenate((new_r, new_g, new_b, new_a), axis=2)
pyexr.write("out.exr", color)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment