RawPy 和 imageio 的组合产生红色图像
我想使用 .dng 文件进行一些图像处理。我正在使用 rawpy 将文件转换为 numpy 数组。然后imageio保存图像。这是一个非常简单的代码,在 rawpy 网页上给出。
生成的 .png 图像并不像我预期的那样。结果非常红,而原始图像则不然。它就像原始图像上的红色叠加层。
我使用的代码是:
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)
原始 dng 图像: https://drive.google.com/file/d/1Ip4U7KvI4-Lit4u7AuaHfoHIkXvGNRFk/view?usp=sharing
生成的 png 图片:https://drive.google.com/file/d/1CyrqJS2Osj3u-jEzLSxSy5eKMUP4csAV/view?usp=sharing
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需添加参数
use_camera_wb=True
即可。根据 文档:
这意味着使用相机在拍摄过程中自动找到的白平衡系数(这些值存储为 DNG 文件的 Exif 数据)。
我不知道为什么默认值是
use_camera_wb=False
。 (这可能是由于使用 Python 包装 LibRaw 的工作效果不佳所致)。在我看来,默认值应该是
use_camera_wb=True
和use_auto_wb=False
。我们还可以选择输出颜色空间:
output_color=rawpy.ColorSpace.sRGB
。颜色看起来不错,但可能还有其他我不知道的陷阱......(我对
rawpy
和LibRaw
没有足够的经验)。输出(缩小):

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):
