Transformation of sensor's colors into sRGB

in Matlab

according to DNG specification


Transformation of camera sensor's output into sRGB values can be done by algorithm from specification of DNG ("digital negative") format. Needed parameters of the image and the camera are taken from metadata of DNG files, created from camera's raw images with Adobe DNG Converter. This works for a large number of camera models.

The following script implements the algorithm from Adobe Digital Negative (DNG) Specification version 1.4.0.0, 2012 (the latest one as for 2018), pages 79-82. The only simplification is absence of supporting of cameras, whose color space has dimensionality >3 (whose G1 and G2 are different colors).

You need one parameter of the photo ("As Shot Neutral" or "As Shot White xy") and several parameters of the camera (in the general case including parameters of individual camera specimen). Majority of the parameters is taken from Exif of the DNG files (you can read it with RawDigger). Matrix variables are given there as a string of numbers, which must fill the matrix row-wise. "As Shot Neutral" can also be obtained without DNG conversion: you can calculate it from "Camera multipliers" given by dcraw (command dcraw-9.27-ms-32-bit.exe -i -v *.ARW). The "Camera multipliers" must be divided by 1024 and inversed. For example, if "Camera multipliers" are [2088 1024 1964 1024] (they are given for R, G1, B, G2), "As Shot Neutral" will be [0.490421 1 0.521385] (given for R, G, B without separation of G1 and G2).

Values of variables corr_col_temp, xy_illum_1 and xy_illum_2 must be googled. Two elements of the corr_col_temp are correlated color temperatures of illuminants from EXIF tags "Calibration Illuminant 1" and "Calibration Illuminant 2" (e.g., if "Calibration Illuminant 1" is "Standard Light A", corr_col_temp(1) is 2856). Variables xy_illum_1 and xy_illum_2 are xy (chromaticity) values of these illuminants.

The script needs two functions:

  function [Mbfd_nl] = bradford(DXX)

  end

  DXX = [95.105 100.000 108.548];

The following script contains matrices of conversion between sRGB and XYZ using reference white D50, taken from Bruce Lindbloom's site.

Given values of parameters of the camera relate to Sony NEX-5. In the case of my camera, "Camera Calibration" matrices (which must describe the difference between individual camera specimen and reference camera) are actually harmful: they cause turning white objects into pinkish and must be ignored.