Skip to content

Demosaicing Mode#

The Demosaicing Mode camera feature allows you to change the method used for demosaicing.

This can help to optimize image quality.

Info

This feature is available for Basler ace 2, boost R, and dart R cameras.

Basler ace U/L cameras also provide a DemosaicingMode parameter but this only serves to enable the PGI Feature Set.

Using the Feature#

Why Use Demosaicing Mode#

Demosaicing, also called debayering, is performed to generate RGB information from the color output of the image sensor.

Basler color cameras always perform demosaicing, even when the pixel format is set to a Bayer format. This is due to the camera's internal image processing.

Your camera provides different methods for demosaicing. By default, the method is determined automatically based on the pixel format set.

Manually adjusting the demosaicing mode can help if the results produced by the automatically chosen method aren't satisfactory for your application.

For example, the camera automatically chooses the Nearest Neighbor method for Bayer pixel formats. This is done to ensure compatibility with older firmware versions. However, the Unilinear method often achieves better results.

Demosaicing Methods#

The following demosaicing methods are available:

Demosaicing Method Description Suitable for Non-Bayer Pixel Formats Suitable for Bayer Pixel Formats
Average Green Uses information from one of the closest pixels or the arithmetic mean of surrounding green pixels. This is the default method for non-Bayer pixel formats if Basler PGI isn't available.
Basler PGI If available, uses the Basler PGI algorithm for advanced demosaicing.
Nearest Neighbor Uses information from one of the closest pixels. This is the default method for Bayer pixel formats and provides best compatibility with previous firmware versions.
Unilinear Uses information from one of the closest pixels or the arithmetic mean of surrounding pixels. Compared to Nearest Neighbor demosaicing, less color artifacts occur at the edges.

Demosaicing Modes#

The following demosaicing modes are available:

  • Auto: The demosaicing method is determined automatically based on the pixel format set.
  • Manual: The demosaicing method can be set manually.

Configuring Demosaicing#

To change the method used for demosaicing:

  1. Set the BslDemosaicingMode parameter to Manual.
  2. Set the BslDemosaicingMethod parameter to the desired demosaicing method, e.g., Unilinear.

Sample Code#

// Enable manual adjustment of the demosaicing method
camera.BslDemosaicingMode.SetValue(BslDemosaicingMode_Manual);
// Set the demosaicing method to Unilinear
camera.BslDemosaicingMethod.SetValue(BslDemosaicingMethod_Unilinear);
INodeMap& nodemap = camera.GetNodeMap();
// Enable manual adjustment of the demosaicing method
CEnumParameter(nodemap, "BslDemosaicingMode").SetValue("Manual");
// Set the demosaicing method to Unilinear
CEnumParameter(nodemap, "BslDemosaicingMethod").SetValue("Unilinear");
// Enable manual adjustment of the demosaicing method
camera.Parameters[PLCamera.BslDemosaicingMode].SetValue(PLCamera.BslDemosaicingMode.Manual);
// Set the demosaicing method to Unilinear
camera.Parameters[PLCamera.BslDemosaicingMethod].SetValue(PLCamera.BslDemosaicingMethod.Unilinear);
/* 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 */
/* Enable manual adjustment of the demosaicing method */
errRes = PylonDeviceFeatureFromString(hdev, "BslDemosaicingMode", "Manual");
CHECK(errRes);
/* Set the demosaicing method to Unilinear */
errRes = PylonDeviceFeatureFromString(hdev, "BslDemosaicingMethod", "Unilinear");
CHECK(errRes);
# Enable manual adjustment of the demosaicing method
camera.BslDemosaicingMode.Value = "Manual"
# Set the demosaicing method to Unilinear
camera.BslDemosaicingMethod.Value = "Unilinear"

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