简体   繁体   中英

Splitting raw image into channels in Python

I have to split raw image (.DNG) into different channels. CV does not support these formats, and I can't find rawpy function for that.

Use rawpy to convert your DNG into a Numpy array like this:

#!/usr/bin/env python3

import rawpy
import imageio

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

Then you can use Numpy to extract the channels and save like this:

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

Or you can use OpenCV cv2.split() to separate the channels:

import cv2

R, G, B = cv2.split(rgb)

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