Re: Color balance in YUV/YCbCr domain

From: Dave Martindale (davem_at_cs.ubc.ca)
Date: 06/04/04


Date: Fri, 4 Jun 2004 05:27:33 +0000 (UTC)

jason@cintec.cuhk.edu.hk (Jason) writes:

>In RGB domain, I can do "Auto Level" to get a color balanced photo by
>working on R, G and B histogram independently. i.e. to widen the
>dynamic range of each color channel to 0-255.

That isn't colour balancing. It might work that way if the brightest
object in the image also happens to be white, but not otherwise.
Auto levels messes with the black level too, which isn't correct if
there isn't anything truly black in the image.

Colour balancing is selecting an area in the image that you know is
colour-neutral, and then scaling the RGB values to make that area
neutral.

>However, in YUV/YCbCr domain, how can I do color balancing? Any work
>around or simple method to do this?

>I tried to derive a color balancing formula from RGB<->YUV matrix.
>However, it seems that direct transformation is very complicated.

If you know what scaling factors are needed to colour-balance the RGB
image, you can write the transformation that maps RGB to RGB' as a 3x3
matrix which is diagonal. You already know the matrix that maps
RGB->YUV and its inverse. So the operation that colour-balances a YUV
image can be described as taking each YUV value, converting to RGB
using the YUV->RGB matrix, applying the colour-balancing matrix, and
then applying the RGB->YUV matrix to convert back to YUV. If you
multiply these three 3x3 matrices together, you get a single 3x3 matrix
that performs the operation on YUV values, yielding a YUV result.
Multiplying three 3x3 matrices together is *not* complicated.

Now, you should be able to figure out the matrix needed working entirely
in YUV. The result of the matrix multiplication above has 9 numbers but
only 3 degrees of freedom, because there were only 3 variables total in
the 3 original matrices. For an area in the input image that you know
is colour-neutral, the input pixel code (Y, U, V) should map to an
output code of (Y, 0, 0). In other words, the luminance should not
change, and the two colour difference components should become zero.
This gives you 3 linear equations in 3 unknowns, which should be easily
solvable. And that gives you the full 3x3 matrix needed to do the
colour balancing.

        Dave



Relevant Pages

  • Re: about Color Format transformation
    ... it will accept RGB or YUV in and allow RGB out only. ... Having said that your code will not reject YUV output if a downstream ... > Hi Iain ...
    (microsoft.public.win32.programmer.directx.video)
  • Re: Need help in converting YUV to RGB using OV7620
    ... Hope you guys can give me some advise on converting the YUV ... THEN consider doing colour conversion. ... the format is best described spatially as ... You cannot work out true RGB until 2nd Y and V has been acquired, ...
    (comp.arch.embedded)
  • Re: Need help in converting YUV to RGB using OV7620
    ... >THEN consider doing colour conversion. ... >You cannot work out true RGB until 2nd Y and V has been acquired, ... >>The formula given in the data sheet to get YUV was as followed ... I did not do any gamma correction but basically I just convert the ...
    (comp.arch.embedded)
  • Re: C : how to export raw YUV to a file ?
    ... Hasn't someone written a PGP client that can ... | put the ugly stuff in headers where I don't have to look at it unless I ... I thought that some lib could directly export from YUV to png. ... I d just need to understand which format WritePNGexpect RGB data to ...
    (comp.programming)
  • Re: Saturn 5th Dec - my PB!
    ... reference star to set the relative intensities in RGB and IR. ... I'd guess colour balancing the planets to be an even more subjective ...
    (uk.sci.astronomy)