简体   繁体   中英

How to read RGB values of picture with rawpy on Python

I'm trying to get the information from a 16bit 'nef' image with Python.

I've been using rawpy to open the file and get a linear output with the image valuer. But now I want to look only at the green channel.

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)

Now I don't know how to go from this to getting the RGB values.

You can get the Red, Green and Blue channels separated and saved like this:

#!/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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM