8000 Produces black(ish) output dng file · Issue #75 · schoolpost/PiDNG · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Produces black(ish) output dng file #75

8000
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
kevflynn opened this issue May 18, 2023 · 6 comments
Open

Produces black(ish) output dng file #75

kevflynn opened this issue May 18, 2023 · 6 comments

Comments

@kevflynn
Copy link

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?

@schoolpost
Copy link
Owner

Can you include a screenshot or sample of the image? What camera is it from?

@IDKiro
Copy link
IDKiro commented Jul 26, 2023

Same problem here, I ran the provided example directly, raw2dng.py, and it successfully reads the image and stores it as custom.dng, but using various tools it reads an all-black image (including using rawpy).

Env: windows 10 + python 3.8.17 (anaconda)

8000

@G-DP
Copy link
G-DP commented Feb 7, 2024

Any update on this issue?

Env: windows 10 + python Python 3.12.1

Latest version of PiDNG installed from GitHub:

python3 -mpip install git+https://github.com/schoolpost/PiDNG.gi

@OParczyk
Copy link
OParczyk commented Mar 4, 2024

I can confirm this issue on debian12 too, both with python3.11 and 3.12.
used PiDNG from GitHub too.
numpy==1.26.4

raw2dng.py with the supplied scene_daylight_211ms_c2.raw16 yields a completely black image.

@OParczyk
Copy link
OParczyk commented Mar 4, 2024

So I just came around to fiddle with it again and I have an interesting observation:
Changing r.options(t, path="", compress=True) to r.options(t, path="", compress=False)
Makes it work again!
(but weirdly to me the resulting .dng file is still only 67% of the original raw filesize, hmm)
^- Thats due to packing, so nothing suspicious there.

For now that'll do as a workaround for me, I'll report back should I find something else regarding this.

@sgarg367
Copy link

@OParczyk Tried your change, but now it generates a corrupted output.
Output file size is increased to 18.5 MB, but still can't open it.

Any luck in making this code work ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants
0