How do you calculate white balance correction from an RGB or YUV image?

Asked 10/11/2013

5 views

2 answers

0

If an image has incorrect white balance, how can you determine the correction to apply mathematically? For example, in RGB, can you compute a correction vector relative to a neutral gray/white target? How does this work if the image is in YUV instead of RGB?

Originally by Photography Stack Exchange contributor. Source · Licensed CC BY-SA 4.0

Photography Stack Exchange contributor

12y ago

2 Answers

3

If you have a known white or grey point, you want to calculate the ratio between the colors so that each is given a factor to multiply by. For example, in your 250,245,255 reference it would be 1.02, 1.0625, 1 since multiplying the sampled values for white would produce an actual white. (255,255,255). Since the sensor should be linearly responsive, this same ratio should be consistent for the entire light range.

The exact math may vary a bit though depending on what type of entry your camera takes, but the principal is generally the same that you are trying to adjust the color channel's values by a factor to reach the corrected value.

Originally by user11392. Source · Licensed CC BY-SA 4.0

user11392

12y ago

0

AI Answer

Generated from our catalog & community — verify before relying on it.

White balance correction is usually done by scaling color channels so a known neutral area becomes neutral. In RGB, if you can identify a patch that should be white or gray, measure its R, G, and B values and multiply each channel by a factor that makes those values equal. Example: if a neutral sample reads (250, 245, 255), the gains would be about 255/250, 255/245, and 255/255, so after scaling it becomes neutral.

This works best when the image data is linear, because the same channel ratios then apply across the tonal range. In practice, camera processing and color spaces can complicate the exact math, but the principle is the same: apply per-channel gains.

Without a known neutral reference—or some human judgment about what in the scene should be neutral—you generally cannot determine the “correct” white balance from RGB values alone. The image data by itself is ambiguous.

For YUV, white balance is still fundamentally a color-channel correction problem, so it is typically easier to think of it in RGB (or the camera’s native sensor data), apply the channel gains there, then convert back if needed.

UniqueBot

AI

12y ago

Your Answer