Colour Science

DNG to sRGB : the output image contains high value

I am trying to develop raw dng image of DeepISP dataset (S7 ISP Dataset | Kaggle). As I want to process raw image with min. processing and want to learn the pipeline of raw space conversion to image what can be viewed without introducing non-linearity (sRGB without gamma and tone).

Following are the steps that I took :

  1. Dcraw Param : Initial dcraw used in lib are (-D -W -4 -t 0 -T), but it does not avoid the default WB therefore I changed to (-r 1 1 1 1 -j -D -W -4 -o 0 -t 0 -T). -r will ensure that not channel is provided any gain.
  2. Read tiff file produced in previous step by dcraw.
  3. Demosaic : Just to keep simple, I tried using bilinear but color-demosaic lib producing demosaic image out of range. This seems to be not possible with bilinear. Therefore switch to opencv for demosaicing and normalize the output again.
  4. Cam_to_XYZ : taking motivation from the dng example HERE , used camera_neutral_to_xy and camera_space_to_XYZ_matrix function to get the cam_to_xyz matrix. After multiplying the matrix with image, everytime image is produce way beyond the [0,1] range. This seems to be fine and illumination after adaptation if by default D50 as it is DNG
  5. XYZ_to_sRGB : after having image in XYZ coordinate, it is required to convert into well known color space for visualization. As sRGB is widely used for the task. Continue same motivation from tutorial, I tried to use XYZ_to_sRGB function with same setting except switching off cat.
  6. After this conversion, i understand i can get negative values due to limitation of color space gamut. However i am getting value in the range of [-0.2 , 3.4]

The upper limit is way beyond the required values. If the upper limit is near 1 like 1.02/1.1, it make sense to clip it. But now, this value is way beyond the upper limit. I don’t want to do gamma at this point to preserve the linearity.

Is there any issue with therotation matrix calculation of cam_to_xyz or xyz_to_srgb? If Library is not handling these cases, how can we handle it?

Similar question asked on github. But I believe ppl are not active in github, therefore asking here again For the community, it is easier to find solution via github, so I will keep that thread open as well.

1 Like

Hi @raviy0807,

Thanks for cross-posting, it seems that most of the discussion is happening on the Github thread!