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 (https://gist.github.com/jadarve/de3815874d062f72eaf230a7df41771b), but it does not save the extracted channels into separate image files
Asked
Active
Viewed 229 times
1
-
The arrays that it returns are floats in the range 0..1 representing a high dynamic range image. You need to give thought as to whether you want that as a *"low dynamic range"* 8-bit JPEG in range 0..255, or a 16-bit PNG in range 0..65535 or a float TIFF which can hold a similar range but will likely look black in many viewers. – Mark Setchell Sep 21 '22 at 10:50
-
I need a 16-bit PNG. But the problem is that I don't know how to save it as a separate file. – Vitaliy V. Sep 21 '22 at 11:16
1 Answers
1
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

Mark Setchell
- 191,897
- 31
- 273
- 432