CSS001
CSS001

Reputation: 21

white balancing algorithm based on user input substance pixelprocessor

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..?

Upvotes: 2

Views: 426

Answers (0)

Related Questions