Raw2DNG color matrix and calibration illuminant

Started by cpc, January 23, 2014, 12:05:58 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

cpc

I'm preping to start doing some post on a few months old raw project shot on 5dm3 and I was checking the DNG files I got. Off-the-camera files were converted with RAWanizer.
What strikes me as odd is that in the resulting .dng files the tag for ColorMatrix1 uses the daylight (D65) matrix, but the corresponding CalibrationIlluminant1 tag is Standard Light A (Tungsten).
There is also no ColorMatrix2 tag, although there is a CalibrationIlluminant2 tag (D65). I had a quick look at the source code and it appears this is coming from raw2dng and not from RAWanizer.

If you wonder what the visual effect of these matricies is in a raw processing software: there is subtle tint movement mostly over the green-magenta axis, but also skin moves subtly from yellow to pink. This can be verified in ACR or Resolve.

I can fix this easily with exiftool, and also add the second color matrix to my files, but before doing this I wonder if there is a specific reason for what looks like a mismatch in the values used in these tags? Thanks.
(I wasn't sure if this is the correct subforum for the question, pls move the post if appropriate)

a1ex

Sure, just tell us exactly what needs to be fixed in EXIF, and we'll fix it.

cpc

As per DNG spec, there are a few tags that define the conversion of the raw data from camera space to XYZ space.

Here they are:
CalibrationIlluminant1       
CalibrationIlluminant2       
ColorMatrix1                 
ColorMatrix2                 
CameraCalibration1     
CameraCalibration2     
ForwardMatrix1           
ForwardMatrix2           
ReductionMatrix1
ReductionMatrix2
AnalogBalance
ProfileHueSatMapDims
ProfileHueSatMapData1
ProfileHueSatMapData2

DNG Converter doesn't produce Reduction Matrices for canon raw files, so these can probably be ignored. AnalogBalance seems to always be 1 1 1.
Everything else is used by ACR when developing a Canon raw file turned into .dng (by Adobe DNG Converter)
Tags with 1 and 2 at the end correspond to the respective calibration illuminant. While using both the illuminants is optional, these allow for a more precise mapping at different white balance settings.

Here is what DNG Converter always outputs from a Canon 5d mark 3 .cr2 raw file:
Calibration Illuminant 1        : Standard Light A
Calibration Illuminant 2        : D65
Color Matrix 1                  : 0.7234 -0.1413 -0.06 -0.3631 1.115 0.285 -0.0382 0.1335 0.6437
Color Matrix 2                  : 0.6722 -0.0635 -0.0963 -0.4287 1.246 0.2028 -0.0908 0.2162 0.5668
Camera Calibration 1            : 0.9923 0 0 0 1 0 0 0 0.9843
Camera Calibration 2            : 0.9923 0 0 0 1 0 0 0 0.9843
Forward Matrix 1                : 0.7868 0.0092 0.1683 0.2291 0.8615 -0.0906 0.0027 -0.4752 1.2976
Forward Matrix 2                : 0.7637 0.0805 0.1201 0.2649 0.9179 -0.1828 0.0137 -0.2456 1.057

These are model based, except Camera Calibration, which in theory is individual camera specific. I guess the way to check if CameraCalibration is indeed individual camera specific is to compare with the same tag from other 5dm3 cameras. CameraCalibration has a noticeable effect on the resulting image (well, with these particular values, at least), slightly boosting reds and blues.

And here is what comes from raw2dng:
Calibration Illuminant 1        : Standard Light A
Calibration Illuminant 2        : D65
Color Matrix 1                  : 0.6722 -0.0635 -0.0963 -0.4287 1.246 0.2028 -0.0908 0.2162 0.5668

Note how the matrix used is actually the matrix for the D65 illuminant (as specified by DNG Converter) but here corresponding to Standard Light A (tungsten) instead. The second illuminant will be ignored by raw processors because there are no matching matrix tags. As a result the raw processor only uses this matrix instead of interpolating between the two based on chosen WB.

ForwardMatrix1 and ForwardMatrix2 are applied by both ACR and Resolve but appear to have a minor effect. I actually expected Resolve to ignore them, as they are absent in BMCC files, but they are applied.

ProfileHueSatMapDims, ProfileHueSatMapData1, ProfileHueSatMapData2 define hue/saturation/value mapping tables which are applied last, and actually have significant impact on the final image in some parts of the color space. These are read and applied by ACR, but ignored by Resolve. Note that these aren't exactly small and add around 64KB to the file. These are binary tags and can be copied from an existing DNG Converter created .dng still onto the video .dng files (by ACR users, anyway).

So I'd suggest adding to the EXIF:
CalibrationIlluminant1       
CalibrationIlluminant2       
ColorMatrix1                 
ColorMatrix2                 
ForwardMatrix1           
ForwardMatrix2           

CameraCalibration1 and CameraCalibration2 should be added only if they turn out to be model specific and not individual camera specific. In the latter case probably an option to specify them explicitly would be nice? Handling the HSV table tags is probably an overkill (and increases size significantly), and it is easy to add with ExifTool anyway.

[Note that the values listed above only apply to 5dm3.]

The above doesn't touch on the black/white levels based on white balance, which is another story.

Hope this helps.

a1ex

Alright, so first problem seems to be a bug in chdk-dng.c (if we only have one matrix, there should be only one illuminant, the D65 one, correct?)

Pull request welcome for this, no real coding skills needed. Patching chdk-dng will fix both raw2dng and mlv_dump.

The second one looks more like an enhancement to me. The matrices are the same in my 5D3 shots, but they are not found in the CR2 (they are introduced by Adobe DNG converter). I'm not sure if there are any copyright restrictions in copying these matrices (we took the current ones from dcraw).

For implementation, I believe it's best handled in the converters (mlv_dump / raw2dng / cr2hdr), because adding more fields to the raw_info structure means changing the file format for both RAW and MLV, so it may break existing converters. MLV saves camera name in metadata, so it's probably easy (though kinda boring) to copy these color matrices and select them based on camera model. Maybe g3gg0 has a better suggestion?

raw2dng doesn't have this metadata (it only has the matrix1 from dcraw, which could be used for a reverse lookup), but it's a legacy format; worth adding this enhancement here?

Andy600

Colorist working with Davinci Resolve, Baselight, Nuke, After Effects & Premier Pro. Occasional Sunday afternoon DOP. Developer of Cinelog-C Colorspace Management and LUTs - www.cinelogdcp.com

cpc

Quote from: a1ex on January 23, 2014, 10:31:56 PM
if we only have one matrix, there should be only one illuminant, the D65 one, correct?

Technically, yes.
Resolve will just use the one matrix supplied over the entire illuminant range anyway. ACR appears to do something more, but the difference between the illuminants is practically imperceptible with the same matrix.
The sizeable difference will only show after the second matrix (and, eventually, the CameraCalibration matrix) is added.
I believe dcraw got their matrices from Adobe. Shouldn't be a problem, these are just numbers. :)

g3gg0

to be honest - i prefer to add this information in the exporting step.
this is much easier to handle than packing that data into ml binaries.

is there a public database of these matrices?
Help us with datasheets - Help us with register dumps
magic lantern: 1Magic9991E1eWbGvrsx186GovYCXFbppY, server expenses: [email protected]
ONLY donate for things we have done, not for things you expect!

Andy600

Quote from: g3gg0 on January 23, 2014, 11:53:12 PM
to be honest - i prefer to add this information in the exporting step.
this is much easier to handle than packing that data into ml binaries.

is there a public database of these matrices?

There is no public database but matrices can be extracted. I'll send you what I have (probably tomorrow) and covers all raw shooting cameras.
Colorist working with Davinci Resolve, Baselight, Nuke, After Effects & Premier Pro. Occasional Sunday afternoon DOP. Developer of Cinelog-C Colorspace Management and LUTs - www.cinelogdcp.com

Marsu42

Quote from: a1ex on January 23, 2014, 10:31:56 PM
For implementation, I believe it's best handled in the converters (mlv_dump / raw2dng / cr2hdr), because adding more fields to the raw_info structure means changing the file format for both RAW and MLV, so it may break existing converters.

Are these features really already in the "feature freeze" state? My feeling is that this whole new raw stuff is so new that some changes - if they are merited by ongoing development - should be ok. However, there should be some upgrade path say from old dual_iso cr2 files to a newer format with extended tags.

Quote from: cpc on January 23, 2014, 11:37:55 PMI believe dcraw got their matrices from Adobe. Shouldn't be a problem, these are just numbers. :)

Are you sure - there are illegal numbers, you know :-p ... https://en.wikipedia.org/wiki/Illegal_number

a1ex

I'm not talking about feature freeze, but about the recording file formats. There are lots of apps that process RAW and MLV files around.

Marsu42

Quote from: a1ex on January 24, 2014, 12:56:39 AM
I'm not talking about feature freeze, but about the recording file formats.

That's what I wanted to say, I didn't find the correct word :-o

Quote from: a1ex on January 24, 2014, 12:56:39 AM
There are lots of apps that process RAW and MLV files around.

Ok, I'll take your word for that - question is how many of these are in current use and not outdated, and how many are actively developed enough so that changes will be quickly made concerning an updated mlv format. I just wanted to add my 2ct no to be too conservative about this if compatibility means a lot of hassle on the dev's side.

Andy600

Here's a weird one - If the 550D, 600D, 60D, 7D etc all share the same sensor, why are the DNG matrices different for each camera?
Colorist working with Davinci Resolve, Baselight, Nuke, After Effects & Premier Pro. Occasional Sunday afternoon DOP. Developer of Cinelog-C Colorspace Management and LUTs - www.cinelogdcp.com

Marsu42

Quote from: Andy600 on January 24, 2014, 01:13:02 AM
Here's a weird one - If the 550D, 600D, 60D, 7D etc all share the same sensor, why are the DNG matrices different for each camera?

Because they aren't the same sensor, it's a common fallacy since they've all got 18mp aps-c ... but Canon seems to have kept tweaking them a bit even before the addition of the dual sensor af pixels.