RAW-PLAIN-16bit open

File is here UPLOAD.EE - RAWPLAIN16.zip - Download

It opens almost properly after i switched extension to .raw, but there’s some obvious problems. Is there any settings to make this file read properly or could you add support for this files?

“format”: “plain”
“width”: 4000
“height”: 3000
“pixelPrecision”: 16
“imageLayout”: “planar”
“pixelType”: “bayer_bggr”

Welcome!

IMHO, you’re much better off converting these to DNG. See e.g. PiDNG and also search the forum for similar questions in the past.

There is something seriously wrong with the raw data - the maximum value recorded is 15 !!

Therefore the converted image will be very dark and not easy to recover.

I’m not sure that one can just “switch extensions” of raw images.

I was able to open it in darktable - first converted to dng with PiDNG, though.

For some reason Rawtherapee does not recognize the file at all (it does not show up in the browser). ART gives an error that it cannot open the file.

Perhaps there should be, for instance, camera name and model in the DNG metadata that are then also defined in some configuration file for those programs (camconst.json or something). I’m not an expert on either program…

I made trivial changes to the example program that comes with PiDNG in order to convert your file. Here is my changes to the raw2dng.py file in the examples folder of PiDNG:

from pidng.core import RAW2DNG, DNGTags, Tag
from pidng.defs import *
import numpy as np
import struct

# image specs
width = 4000
height = 3000
bpp= 16

# load raw data into 16-bit numpy array.
numPixels = width*height
#rawFile = '../extras/scene_daylight_211ms_c2.raw16'
rawFile = '../extras/RAWPLAIN16.raw'
rf = open(rawFile, mode='rb')
rawData = struct.unpack("H"*numPixels,rf.read(2*numPixels))
rawFlatImage = np.zeros(numPixels, dtype=np.uint16)
rawFlatImage[:] = rawData[:]
rawImage = np.reshape(rawFlatImage,(height,width))
#rawImage = rawImage >> (16 - bpp)
rawImage *= 64

# 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, bpp)
t.set(Tag.CFARepeatPatternDim, [2,2])
t.set(Tag.CFAPattern, CFAPattern.BGGR)
t.set(Tag.BlackLevel, (4096 >> (16 - bpp)))
t.set(Tag.WhiteLevel, ((1 << bpp) -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=False)
r.convert(rawImage, filename="custom")

Of course most of the parameters are still wrong above, but I think this shows it can be done.

I hope this helps,

Harri

1 Like

It’s not a Samsung raw file. What the OP posted is just a memory dump of the image buffer.

Thanks, that makes sense … here’s what FastRawViewer sees:

Looks like PiDNG applied a lot of exposure …

Looks like the file contains 10 bit data, stored in the lowest bits. I didn’t spend much time trying to figure out the correct settings for PiDNG - I simply multiplied the pixel values by 64… not very elegant, but I just wanted to see if the file can be opened in different applications.

I still haven’t figured out why RawTherapee and ART don’t open the DNG. Something is missing, but what?

1 Like

There are good few variations of “a DNG”. This one might be, for example, a ‘Linear DNG’ which is not universally accepted by editors/viewers

The code is there. There is no “might be”.

no comment.

Hi,

Can the dng be downloaded from somewhere? If so, I’ll have a look.

Best

Either this, or simply leave WhiteLevel at 1023 if you’re sure only 10 LSBs are used. (And fudge BlackLevel accordingly, i.e. set bpp=10, but it would ultimately need to be calibrated along with the color matrix and neutral white.)

Out of interest, I opened the dark image and GIMPed it with Exposure then Brightness/Contrast. Observe the not-unexpected curved banding in the sky:

I hope the following link works:

This is a different image, it is the example image that comes with PiDNG. Perhaps a better starting point, since the metadata is more likely to be correct.

The image opens in darktable, and looks about fine there. In ART there is just an error “Cannot load image …” (and a the thumbnail is blank).

Thanks,
Harri

Just to let you know this image opens w/o errors w/ rawpy (LibRaw wrapper), but is completely black. So I guess there might be something going on w/ the script metadata… Even the unprocessed_raw from the LibRaw tools extracts a black raw image.

Apart from duplicated DNGVersion and DNGBackwardVersion tags (but that shouldn’t throw errors), it is forbidden by the TIFF/DNG spec to have both strip and tile related tags together, those are meant to be exclusive - the file layout is either strip based or tile based (hello Sony!).

So in your modified script please remove the tile related ones, and add RowsPerStrip (equal to image height) instead. (And you can remove the extra DNGVersion and DNGBackwardVersion setting, those seem to be created w/ the class anyway; one can also drop PreviewColorSpace as there is no embedded preview anyway).

Bonus points if you report/fix this upstream :wink:

Wow, thanks @kmilos! After the changes you suggested, now it works. The image opens correctly in both ART and Rawtherapee.

Here is a link to the fixed dng, if anyone is interested:

And how it looks in ART:

@Roman: are you still interested in converting your images? You could use Python with the PiDNG code (+ some modifications to it as above) to convert your images to DNG, and those you can then open in RawTherapee.

2 Likes