-
Notifications
You must be signed in to change notification settings - Fork 43
Description
I am trying to convert a raw photo using the following code (from the example)
`from pidng.core import RAW2DNG, DNGTags, Tag
from pidng.defs import *
import numpy as np
import struct
import rawpy
import sys
load raw data into 16-bit numpy array.
raw_file = sys.argv[1]
output_file = sys.argv[2]
with rawpy.imread(raw_file) as raw:
width, height = raw.raw_image.shape
bit_depth = raw.raw_image.dtype.itemsize * 8 # bytes to bits
raw_image = raw.raw_image
num_pixels = width * height
uncalibrated color matrix, just for demo.
ccm1 = [
[19549, 10000],
[-7877, 10000],
[-2582, 10000],
[-5724, 10000],
[10121, 10000],
[1917, 10000],
[-1267, 10000],
[-110, 10000],
[6621, 10000],
]
set DNG tags.
t = DNGTags()
t.set(Tag.ImageWidth, width)
t.set(Tag.ImageLength, height)
t.set(Tag.TileWidth, width)
t.set(Tag.TileLength, height)
t.set(Tag.Orientation, Orientation.Horizontal)
t.set(Tag.PhotometricInterpretation, PhotometricInterpretation.Color_Filter_Array)
t.set(Tag.SamplesPerPixel, 1)
t.set(Tag.BitsPerSample, bit_depth)
t.set(Tag.CFARepeatPatternDim, [2, 2])
t.set(Tag.CFAPattern, CFAPattern.GBRG)
t.set(Tag.BlackLevel, (4096 >> (16 - bit_depth)))
t.set(Tag.WhiteLevel, ((1 << bit_depth) - 1))
t.set(Tag.ColorMatrix1, ccm1)
t.set(Tag.CalibrationIlluminant1, CalibrationIlluminant.D65)
t.set(Tag.AsShotNeutral, [[1, 1], [1, 1], [1, 1]])
t.set(Tag.BaselineExposure, [[-150, 100]])
t.set(Tag.Make, "Camera Brand")
t.set(Tag.Model, "Camera Model")
t.set(Tag.DNGVersion, DNGVersion.V1_4)
t.set(Tag.DNGBackwardVersion, DNGVersion.V1_2)
t.set(Tag.PreviewColorSpace, PreviewColorSpace.sRGB)
save to dng file.
r = RAW2DNG()
r.options(t, path="", compress=True)
r.convert(raw_image, filename=output_file)
`
and it's producing an image - but the image is just a black blur. I suspect it's because I'm not changing the color matrix settings? I don't know how to configure that - any guidance on that? or anything else that could be causing this?