Browse KB Articles
Using White Balance with Blackfly S and Spinnaker
KB Number: 11109
Blackfy®S and Spinnaker® SDK
Application Note Description
This document provides a description of White Balance used by the Blackfly S camera.
Color Processing Pipeline
What is White Balance?
White Balance is the adjustment of image basis color intensities (Red, Green, and Blue color channels). White Balance is also known as Color Balance or Gray Balance and is used to change the overall appearance of an image, based on various lighting conditions, to reflect what our eyes see.
White balance scales the three color components (RGB) in an image to account for lighting conditions. Lighting conditions play a role in how an image looks.
Why is White Balance Important?
A Raw color image is usually presented as a monochromatic image until all the colors are interpolated. Once converted to a color image via an interpolation method, the image has color. Interpolation is a method of reconstructing color for an entire color image when a subset of the pixel color values are not available. This article does not focus on how interpolation works, but highlights the consequences of interpolating non-white-balanced images.
The example below was taken under fluorescent lighting. The image on the left was taken without white balance enabled. The image on the right has white balance applied to adjust the color, compensating for the lighting conditions and providing results that more closely resembles what the human eye sees.
One theory in white balancing is that an image is generally “gray”, meaning that the intensities of the Red, Green and Blue color channels should be roughly equal. This type of color balance is called Gray World Theorem. Fundamentally, unless an image is predominately green, red, or blue this theory typically produces a balanced image.
Image histogram data provides a method of analyzing how close white balance is at making an image closer to human perception. In the examples below, the first image does not have white balance and the second image has white balance applied. The image with white balance enabled shows a more even distribution of intensity for the Red, Green, and Blue color channels.
Histogram for image without white balance enabled
Histogram for image with white balance enabled
How is White Balance Implemented?
There are two ways in which a color channel can be scaled:
In the first method, to find a scaling coefficient for each color channel, the coefficients are not referenced against the nominal brightness of the image. That is why most white balancing scale two color channels against a color reference. The typical color reference used is green since green is the most dominant Bayer tile color.
The white balancing coefficients can then be written as below:
The coefficients can then be calculated by using the average color channel values.
Blackfly S cameras use Green/Red and Green/Blue ratios when calculating white balance.
Automatic White Balance
The Gray World Theorem can be implemented as a linear function algorithm, meaning it is not computationally intensive, and therefore is used onboard the camera to calculate white balance values. Blackfly S cameras use a modified version of the gray world theorem in auto white balance mode. The algorithm sums the Red, Green, and Blue channels and then calculates the appropriate alpha and beta.
Auto white balance can be set to run continuously on image capture to adapt to varying lighting conditions. There are four parameters that can be configured on Blackfly S cameras to provide the user with more control over white balance.
How to Enable Auto White Balance
Auto white balance may be enabled in SpinVIew or in the Spinnaker API.
To enable auto white balance using SpinView:
1. Navigate to the Settings tab.
2. Set Balance White Auto to either Continuous or Once.
3. Navigate to the Features tab.
4. Select the appropriate white balance auto profile - either indoor or outdoor.
5. Set the upper and lower limit of Auto White Balance.
6. Set the White Balance Auto Damping field to the time constant for the auto feature.
You can optionally use a specific region of interest (ROI) to white balance the entire image. To do so:
To enable auto white balance using Spinnaker API C++:
//Enabling Auto White Balance setting limits and damping constant.
//Setting White Balance ROI (note that the WB ROI cannot be greater than ROI subsampling on the image.
How to Manually Adjust White Balance Ratios
The white balance ratios may be adjusted in SpinView or by using the Spinnaker API.
To adjust white balance using SpinView:
To enable manual white balance using Spinnaker API C++:
// Retrieve nodes for manually adjusting white balance settings.