How to extract and save as separate files the RGBA and Z channels from an EXR file in Python?


Tell me, how I can extract individual channels from an exr image? This feature is in Photoshop and After Effects, but I would like to do it with code. I found the required code here (, but it does not save the extracted channels into separate image files

Asked By: Vitaliy V.



So, if you have img with shape (height, width, 3) and it is float, and in RGB order, you need:

import cv2

... existing code

# Change to range 0..65535
img = (img * 65535).astype(np.uint16)
# Change from RGB to BGR ordering
imgBGR = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
# Save to disk
cv2.imwrite('result.png', imgBGR)

# Now do,likewise for depth data
z = (z * 65535).astype(np.uint16)
cv2.imwrite('z.png', z)

If you have RGBA, use cv2.COLOR_RGBA2BGRA

Answered By: Mark Setchell
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.