Darktable white balance error with new Android DNGs

Hi,
I’ve been happily using DT 4.2 for months now to edit and develop my DNG files produced with my Pixel 4A with excellent results.
A few days ago, after a Android update I saw huge problems with color balance. I’m using Manjaro, so still no DT 4.4 here.
I attach two images: one old that works OK and one new producing an error and horrible color cast and I show also the Android versions: HDR+ 1.0.520435816zd (old) and HDR+ 1.0.538010570zd (new)
20230625_0009.dng (17.5 MB)
20230519_0001.dng (17.0 MB)

image
image


ciao!
marco

1 Like

I forgot to add that RawTherapee works OK with both versions, so it seems an issue with DT.

I have the same issue with Pixel 4a images, but not Pixel 6a images.

Thankfully, the Pixel raws mostly seem to have a baked-in white balance, so presetting a fixed color calibration seems to do the trick as a workaround.

Looks like they decided to change the input color profile, this is before:

ColorMatrix2                    : 1.0626 -0.4466 -0.1116 -0.4205 1.2766 0.1562 -0.0739 0.2132 0.5474

and this after (D65 calibration also moved to set 1):

ColorMatrix1                    : 0.8456 -0.4018 -0.1301 -0.9956 1.9269 0.0401 0.026 -0.0989 0.5153

Very different. dt is just using what it’s fed.

OK, but RT is working fine and anyway dt is producing an error related to color balance.

I think that white balance error is because you use color calibration to set white balance while the white-balance is not set to ‘reference’.

This isn’t a problem of you know what you are doing , but a thing to try it to take the color calibration and reset ir ro ‘as shot’ (no matter what the white balance module is set to)

Did you try disabling the color calibration module?

Comparing the dng files from the old and new versions there are a few other differences…

AsShotNeutral tag has been replaced by AsShotWhiteXY tag:

Exif.Image.AsShotWhiteXY                     Rational    2  337129/1000000 299811/1000000

There are these new tags from the DNG 1.6 spec that add a third “as shot” illuminant:

Exif.Image.CalibrationIlluminant3            Short       1  Other light source
Exif.Image.CameraCalibration3                SRational   9  10000/10000 0/10000 0/10000 0/10000 10000/10000 0/10000 0/10000 0/10000 10000/10000
Exif.Image.ColorMatrix3                      SRational   9  6710/10000 -2129/10000 -821/10000 -5130/10000 14035/10000 1105/10000 -894/10000 1974/10000 4153/10000
Exif.Image.ForwardMatrix3                    SRational   9  5982/10000 2747/10000 914/10000 2193/10000 8540/10000 -733/10000 163/10000 -2575/10000 10663/10000
Exif.Image.IlluminantData3                   Undefined  18  0 0 243 134 147 21 0 0 0 64 242 27 48 19 0 0 0 64

Decoding the IlluminantData3 tag it contains the same xy values as the AsShotWhiteXY tag, and the ColorMatrix3 varies from shot to shot.

I tried opening one of the new dngs in Google’s own Snapseed Android app and it can’t read them at all, although it works with the older dngs.

My 4a DNGs started behaving the very same way (and I don’t use the color calibration module).

Interesting, it looks like in addition to the move to adding ColorMatrix3 etc from DNG 1.6, they dropped the Profile HueSatMap tables - which are frequently used to handle extremely saturated colors better.

Sadly while they are now using DNG 1.6 features, they’re still not saving as a demosaiced image which they SHOULD be doing whenever their MFSR stacking mechanism is used.

1 Like

I’m still trying to figure out what is going on here… the Adobe DNG SDK comes with a utility dng_validate which checks the validity of a dng file and can also run it through the entire processing pipeline outputting a sRGB TIFF. So we can consider that a sort of reference implementation for how to properly interpret the file.

Using the cmake setup of raw2dng I built a Linux executable of dng_validate from DNG SDK 1.6. The source is here: GitHub - paolodepetrillo/raw2dng at adobe_dng_validate_sdk16
To build and run, check out and:

mkdir build
cd build
cmake ..
make
./dng_validate/dng_validate

I shot a spydercheckr under daylight and halogen. For the unmodified dng files, the output looks reasonable - no severe color or white balance issue. In this case the DNG SDK sees that it is a triple illuminant v1.6 DNG and would use the ColorMatrix3 / ForwardMatrix3 since the AsShotWhiteXY exactly matches the IlluminantData3. darktable and most other apps do not use these DNG 1.6 tags at all so would never use this matrix.


I then removed the new tags so that it would handle it like a pre-1.6 dual illuminant dng:

exiftool -m -ColorMatrix3= -ForwardMatrix3= -CalibrationIlluminant3= image.dng

Now it’s using the ColorMatrix1/2 - darktable would use the daylight one of these two. Now the output is much less saturated, but the white balance still seems approximately ok, not way off like it would be if these files were opened in darktable or some other editors.


I also removed the matrix for StdA (incandescent) illuminant leaving only the D65 (daylight) matrix:

exiftool -m -ColorMatrix2= -ForwardMatrix2= -CalibrationIlluminant2= image.dng

This is exactly how darktable would handle the file, using only the D65 matrix and ignoring the others. The white balance is still not obviously wrong:


So maybe the white balance is wrong in darktable because it’s misinterpreting the rarely used AsShotWhiteXY tag? All the other dng files I’ve ever seen use the other alternative AsShotNeutral tag.

1 Like

Please help in testing Improved calculation of DNG white balance from AsShotWhiteXY by kmilos · Pull Request #515 · darktable-org/rawspeed · GitHub

That’s definitely an improvement. Now when selecting ‘as shot’ WB in the temperature module and not using color calibration, it sets reasonable channel coefficients. For a daylight shot it set coefficients that were pretty close to the ones I got by picking a gray patch on the color checker.

There is still another issue (unrelated to this fix) when trying to use modern WB with color calibration - when selecting ‘camera reference’ in temperature module, the D65 coefficients it derives from the dng’s color matrix are way off. This didn’t happen with the old color matrix from before they changed the profile. With the AsShotWhiteXY patch to rawspeed, color calibration set to ‘as shot in camera’ is able to correct it somewhat, but only by setting an illuminant with very high chroma.

1 Like

Thanks for testing. No idea how the color calibration module works, so this will have to be looked at by someone else…