alxg
alxg

Reputation: 368

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.

Upvotes: 2

Views: 2011

Answers (1)

Mark Setchell
Mark Setchell

Reputation: 207798

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)

Upvotes: 3

Related Questions