RawPy 和 imageio 的组合产生红色图像

发布于 2025-01-16 02:05:51 字数 796 浏览 5 评论 0原文

我想使用 .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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

各空 2025-01-23 02:05:51

只需添加参数 use_camera_wb=True 即可。

根据 文档

use_camera_wb (bool) – 是否使用拍摄时的白平衡值

这意味着使用相机在拍摄过程中自动找到的白平衡系数(这些值存储为 DNG 文件的 Exif 数据)。

我不知道为什么默认值是 use_camera_wb=False。 (这可能是由于使用 Python 包装 LibRaw 的工作效果不佳所致)。
在我看来,默认值应该是 use_camera_wb=Trueuse_auto_wb=False

我们还可以选择输出颜色空间:output_color=rawpy.ColorSpace.sRGB

颜色看起来不错,但可能还有其他我不知道的陷阱......(我对 rawpyLibRaw 没有足够的经验)。


import rawpy
import imageio

path = r'img\CGraw.dng'

with rawpy.imread(path) as raw:
    rgb = raw.postprocess(use_camera_wb=True, use_auto_wb=False, output_color=rawpy.ColorSpace.sRGB)
    
imageio.imsave(r"img\spyraw.png",rgb)

输出(缩小):
输入图片此处描述

Simply add the argument use_camera_wb=True.

According to the documentation:

use_camera_wb (bool) – whether to use the as-shot white balance values

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 and use_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 and LibRaw).


import rawpy
import imageio

path = r'img\CGraw.dng'

with rawpy.imread(path) as raw:
    rgb = raw.postprocess(use_camera_wb=True, use_auto_wb=False, output_color=rawpy.ColorSpace.sRGB)
    
imageio.imsave(r"img\spyraw.png",rgb)

Output (downscaled):
enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文