首页 > 解决方案 > 如何在 Python 上使用 rawpy 读取图片的 RGB 值

问题描述

我正在尝试使用 Python 从 16 位“nef”图像中获取信息。

我一直在使用rawpy图像估值器打开文件并获得线性输出。但现在我只想看绿色通道。

path = 'image.nef' 
with rawpy.imread(path) as raw:
    rgb_linear = raw.postprocess(gamma=(1,1),no_auto_bright=True, output_bps=16) 
    rgb= raw.postprocess(no_auto_bright=True, output_bps=16)

现在我不知道如何从这里获取 RGB 值。

标签: python-3.ximagergb

解决方案


您可以像这样分离并保存红色、绿色和蓝色通道:

#!/usr/bin/env python3

import rawpy
import imageio

with rawpy.imread('raw.nef') as raw:
    rgb = raw.postprocess(gamma=(1,1), no_auto_bright=True, output_bps=16)

# Extract Red, Green and Blue channels and save as separate files
R = rgb[:,:,0]
G = rgb[:,:,1]
B = rgb[:,:,2]

imageio.imsave('R.tif', R)
imageio.imsave('G.tif', G)
imageio.imsave('B.tif', B)

推荐阅读