I want to do some image processing using .dng files. I am using rawpy to convert the file into a numpy array. Then imageio to save the image. It is a very simple code, given on the rawpy webpage.
The resulting .png image is not as I expect it to be. The result is very red, while the raw image isn't. It is like a red overlay on the original image.
The code I am using is:
import rawpy
import imageio
path = r'img\CGraw.dng'
with rawpy.imread(path) as raw:
rgb = raw.postprocess()
imageio.imsave(r"img\spyraw.png",rgb)
Original dng image: https://drive.google.com/file/d/1Ip4U7KvI4-Lit4u7AuaHfoHIkXvGNRFk/view?usp=sharing
Resulting png image: https://drive.google.com/file/d/1CyrqJS2Osj3u-jEzLSxSy5eKMUP4csAV/view?usp=sharing
Simply add the argument
use_camera_wb=True
.According to the documentation:
That means using the white balance coefficients that the camera found automatically during the shot (the values are stored as Exif data of the DNG file).
I don't know why the default is
use_camera_wb=False
. (It could be a result of poor job wrapping LibRaw with Python).In my opinion the default supposed to be
use_camera_wb=True
anduse_auto_wb=False
.We may also select the output Color Space:
output_color=rawpy.ColorSpace.sRGB
.The colors looks right, but there may be other pitfalls that I am not aware of... (I don't have enough experience with
rawpy
andLibRaw
).Output (downscaled):