uci-rendering / psdr-cuda

Path-space differentiable renderer
BSD 3-Clause "New" or "Revised" License
155 stars 11 forks source link

How to convert .exr to .png or vice versa #14

Closed JOP-Lee closed 2 years ago

JOP-Lee commented 2 years ago

Thanks for providing the optimization code in #11. I have found that you compute loss with the rendered result directly. In the example code, the rendered results are stored as a .exr file. I wonder how can I convert the .exr format to the .png format, which is the format for my target image, or vice versa. Thank you very much.

andyyankai commented 2 years ago

python opencv library have all these features. But make sure you understand exposure conversion between exr and png/jpg first. for example:

import cv2
import numpy as np

I = cv2.imread("illya.jpg", cv2.IMREAD_UNCHANGED)
exrI= np.power(I / 255., 2.2).astype("float32")
exrI= cv2.resize(exrI, dsize=(1024, 1024))
cv2.imwrite("illya.exr", exrI)
JOP-Lee commented 2 years ago

Thanks for your reply, I don't know much about the high dynamic range images. How can I find the documentation about the exposure conversion? And I have found that the range of the .exr image after the conversion you provided is between 0 and 1. However, the range of the example ballroom_1k.exr is between 0 and 141. Is this caused by exposure conversion? What should I do if I want to convert the .exr image rendered by psdr into a .png image?

andyyankai commented 2 years ago

Here is an example img = some_integrator.renderC(sc, idx).numpy().reshape((height, width, 3)) im = np.power(img, 1/2.2) im = np.uint8(np.clip(im * 255., 0., 255.)) cv2.imwrite("illya.png", im)