shusheer
Posts: 18
Joined: Wed Oct 28, 2015 3:36 pm

Converting white balance between images

Mon Mar 13, 2017 3:19 pm

Hello All,
(but probably mostly hello to those who know the insides of the camera pipe!)

I have been trying to work out the exact relationship between the AWB values that are captured with images and the processing of the image data to simulate an image taken with a different set of white balance gains.

Specifically, I have two .jpg images taken under slightly different conditions, which have a change in white balance, and I want to put them both into a common white balance (possibly the midpoint between them, or one into the other, or whatever works). The gains were recorded with the images when taken, so I wish to use this recorded information to inter-convert the images.

I _think_ the white balance is applied after de-bayering, before application of the CCM and before colour space conversions from RGB to others - but that is only implied here: viewtopic.php?f=43&t=164033&p=1059684&h ... g#p1059684

What this seems to mean is that I would need to dis-apply the various colour space conversions and CCM, adjust the R/B white balance values, and go back through that process.

Do I have this approximately correct? Is there an easier way to do this?

(NB: It does not appear to be a simple case of scaling the images in sRGB space at output, and yes, I am aware that in reprocessing like this I will likely lose a couple of bits of colour precision as these corrections should be done with 10+ bit data, not 8-bit data. And no, I don't want to force a particular set of gains for all images as my scenes do change in lighting so AWB gets approximately the right correction over time.)

Any hints/tips/suggestions or pointers to relevant code most appreciated.

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 9332
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Converting white balance between images

Mon Mar 13, 2017 6:08 pm

There's two parts: the gain block (red, blue, and overall) in the Bayer domain, and a colour correction CCM in RGB immediately after demosaicing.
In theory you could reverse the conversion matrices. Convert the YUV back to RGB, and then invert the matrices and red/blue gains, before rolling forward with new values. It won't be perfect as the red/blue gains are before demosaicing so will have affected the image during the interpolation, but it's the best you'll manage in the absence of the raw images.
OpenCV or possibly Python's numpy array handling may be the easiest tools for doing this.

If you want to do this more frequently, then grab the raw Bayer images as well.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

Return to “Camera board”