Balance White Auto

The Balance White Auto camera feature automatically corrects color shifts in images acquired.

The pixel data for the auto function can come from one or multiple auto function ROIs.

To correct color shifts manually, use the Balance White feature.

In this topic Hide

Using the Feature

Prerequisites

Enabling or Disabling Balance White Auto

To enable or disable the Balance White Auto auto function, set the BalanceWhiteAuto parameter to one of the following operating modes:

How It Works

Automatic white balancing is a two-step process:

  1. The camera compares the average gray values of the red, green, and blue pixels. It determines the color with the highest average gray value (i.e., the brightest color) and sets the BalanceRatioAbsBalanceRatio parameter value for this color to 1.
  2. The camera automatically adjusts the BalanceRatioAbsBalanceRatio parameter values of the other two colors until the average gray values for red, green, and blue are identical.

As a result, the BalanceRatioAbsBalanceRatio parameter is set to 1 for one color and to a value between 1 and ≈15.98 for the other two colors.

Example: Assume the green pixels in your image have the highest average gray value. If you enable the Balance White Auto auto function, the camera sets the BalanceRatioAbsBalanceRatio parameter value for green to 1. Then, the camera automatically adjusts the BalanceRatioAbsBalanceRatio parameter values for red and blue until the average gray values for red, green, and blue are identical. The new balance ratios could be, e.g., green = 1, red = 1.08789, and blue = 2.19678.

Sample Code

// Select auto function ROI 2
camera.AutoFunctionAOISelector.SetValue(AutoFunctionAOISelector_AOI2);
// Enable the Balance White Auto auto function 
// for the auto function ROI selected
camera.AutoFunctionAOIUsageWhiteBalance.SetValue(true);
// Enable Balance White Auto by setting the operating mode to Continuous
camera.BalanceWhiteAuto.SetValue(BalanceWhiteAuto_Continuous);
// Select auto function ROI 2
camera.AutoFunctionROISelector.SetValue(AutoFunctionROISelector_ROI2);
// Enable the Balance White Auto auto function 
// for the auto function ROI selected
camera.AutoFunctionROIUseWhiteBalance.SetValue(true);
// Enable Balance White Auto by setting the operating mode to Continuous
camera.BalanceWhiteAuto.SetValue(BalanceWhiteAuto_Continuous);
INodeMap& nodemap = camera.GetNodeMap();
// Select auto function ROI 2
CEnumerationPtr(nodemap.GetNode("AutoFunctionAOISelector"))->FromString("AOI2");
// Enable the Balance White Auto auto function
// for the auto function ROI selected
CBooleanPtr(nodemap.GetNode("AutoFunctionAOIUsageWhiteBalance"))->SetValue(true);
// Enable Balance White Auto by setting the operating mode to Continuous
CEnumerationPtr(nodemap.GetNode("BalanceWhiteAuto"))->FromString("Continuous");
// Select auto function ROI 2
CEnumerationPtr(nodemap.GetNode("AutoFunctionROISelector"))->FromString("ROI2");
// Enable the Balance White Auto auto function
// for the auto function ROI selected
CBooleanPtr(nodemap.GetNode("AutoFunctionROIUseWhiteBalance"))->SetValue(true);
// Enable Balance White Auto by setting the operating mode to Continuous
CEnumerationPtr(nodemap.GetNode("BalanceWhiteAuto"))->FromString("Continuous");
// Select auto function ROI 2
camera.Parameters[PLCamera.AutoFunctionAOISelector].SetValue(PLCamera.AutoFunctionAOISelector.AOI2);
// Enable the Balance White Auto auto function
// for the auto function ROI selected
camera.Parameters[PLCamera.AutoFunctionAOIUsageWhiteBalance].SetValue(true);
// Enable Balance White Auto by setting the operating mode to Continuous
camera.Parameters[PLCamera.BalanceWhiteAuto].SetValue(PLCamera.BalanceWhiteAuto.Continuous);
// Select auto function ROI 2
camera.Parameters[PLCamera.AutoFunctionROISelector].SetValue(PLCamera.AutoFunctionROISelector.ROI2);
// Enable the Balance White Auto auto function
// for the auto function ROI selected
camera.Parameters[PLCamera.AutoFunctionROIUseWhiteBalance].SetValue(true);
// Enable Balance White Auto by setting the operating mode to Continuous
camera.Parameters[PLCamera.BalanceWhiteAuto].SetValue(PLCamera.BalanceWhiteAuto.Continuous);
// Select auto function ROI 2
Pylon.DeviceFeatureFromString(hdev, "AutoFunctionAOISelector", "AOI2");
// Enable the Balance White Auto auto function
// for the auto function ROI selected
Pylon.DeviceSetBooleanFeature(hdev, "AutoFunctionAOIUsageWhiteBalance", true);
// Enable Balance White Auto by setting the operating mode to Continuous
Pylon.DeviceFeatureFromString(hdev, "BalanceWhiteAuto", "Continuous");
// Select auto function ROI 2
Pylon.DeviceFeatureFromString(hdev, "AutoFunctionROISelector", "ROI2");
// Enable the Balance White Auto auto function
// for the auto function ROI selected
Pylon.DeviceSetBooleanFeature(hdev, "AutoFunctionROIUseWhiteBalance", true);
// Enable Balance White Auto by setting the operating mode to Continuous
Pylon.DeviceFeatureFromString(hdev, "BalanceWhiteAuto", "Continuous");
/* Macro to check for errors */
#define CHECK(errc) if (GENAPI_E_OK != errc) printErrorAndExit(errc)
GENAPIC_RESULT errRes = GENAPI_E_OK;  /* Return value of pylon methods */
/* Select auto function ROI 2 */
errRes = PylonDeviceFeatureFromString(hdev, "AutoFunctionAOISelector", "AOI2");
CHECK(errRes);
/* Enable the Balance White Auto auto function */
/* for the auto function ROI selected */
errRes = PylonDeviceSetBooleanFeature(hdev, "AutoFunctionAOIUsageWhiteBalance", 1);
CHECK(errRes);
/* Enable Balance White Auto by setting the operating mode to Continuous */
errRes = PylonDeviceFeatureFromString(hdev, "BalanceWhiteAuto", "Continuous");
CHECK(errRes);
/* Select auto function ROI 2 */
errRes = PylonDeviceFeatureFromString(hdev, "AutoFunctionROISelector", "ROI2");
CHECK(errRes);
/* Enable the Balance White Auto auto function */
/* for the auto function ROI selected */
errRes = PylonDeviceSetBooleanFeature(hdev, "AutoFunctionROIUseWhiteBalance", 1);
CHECK(errRes);
/* Enable Balance White Auto by setting the operating mode to Continuous */
errRes = PylonDeviceFeatureFromString(hdev, "BalanceWhiteAuto", "Continuous");
CHECK(errRes);

You can also use the pylon Viewer to easily set the parameters.