2

I'm trying to implement a white balancing workflow similar to what you see in Photoshop if you open a RAW image file. That is:

  1. Open RAW file
  2. Dialog opens that allows user to sample a color from the image (usually one chooses a color that has a mid-grey value
  3. Image is white balanced

I'm trying to implement a similar workflow in another application (just to cut down on application jumping). Currently, I'm doing the following (where the 'source' is the image and the 'target' is the sampled color:

  1. transform source and target images from linear RGB to XYZ space
  2. transform source and target images from XYZ to LMS space using Bradford transform
  3. calculate the scaling coefficients: cr = Lt/Ls, cg = Mt/Ms, cb = St/Ss
  4. multiply each texel in source by diagonal matrix [ cr, 0, 0, 0, cg, 0, 0, 0, cb]
  5. transform source image from LMS space back to XYZ space
  6. transform source image from XYZ space to RGB space

I'm basing this process off of this paper: https://www.hindawi.com/journals/mpe/2014/760123/

and i'm using precomputed transform matrices to transform from RGB to XYZ from here (D65 white point): http://brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html

and the precomputed Bradford transform to transform from XYZ to LMS from here (again, D65 white point): was pulled from the hindawi paper above from part 2ii

I don't have any sample code. I'm trying to implement this in Substance Designer using the Pixel Processor. At this point I'm just curious if my overall approach is sound before diving into the specific implementation.

The output I'm getting from this is hue shifted towards green and too dark.

pre-white balancing in Photoshop: img

after white balancing in Photoshop: img

my results: img

Am I calculating the scaling coefficients in the wrong space? I assume scaling the source texels should happen in LMS space..?

Daniel Widdis
  • 8,424
  • 13
  • 41
  • 63
CSS001
  • 21
  • 1
  • I think youre overthinking it ... I would start doing this in RGB only at first [White balance (Color Suppression) Formula?](https://stackoverflow.com/a/33776667/2521214) and when working then try more advanced stuff. You most likely hit some range limit or use wrong interval like `<0,1>` instead of `<0,255>` or vice versa ... or misplaced the order of channels etc ... – Spektre Jul 24 '19 at 07:42
  • thanks for your reply. Its possible i'm over complicating it, but i don't think i have the channel order wrong or am out of range for the color channels because i can cut out all of the work to find the scaling coefficients and actual scaling (so i only have the transforms to XYZ and then LMS and back to RGB and the output is identical to the input. I think most of the DT like Von Kries requires the colors to be in [0,1] range which I think is the range Substance stores its color data in. – CSS001 Jul 24 '19 at 18:03

0 Answers0