Shading Correction#
Shading correction is based on files that are stored on the camera and contain appropriate correction data. During image acquisition, these are applied to the original pixel values, which results in an improved image.
The Shading Correction feature is only available on racer 2 cameras.
该功能的使用#
运作原理#
DSNU and PRNU Correction#
Shading correction minimizes image artifacts caused by dark signal non-uniformities (DSNU) and photo response non-uniformities (PRNU). The following two types of shading correction are available on the camera:
-
DSNU correction: When the camera captures a line in complete darkness, all of the pixel values in the line should be near zero and they should be equal. In practice, slight variations in the performance of the pixels in the sensor will cause some variation in the pixel values output from the camera when the camera is capturing lines in darkness. DSNU correction corrects for this type of variation. It works by adding an individual gray value (offset) to each pixel value in the lines acquired.
-
PRNU correction: When the camera captures a line while being pointed at a bright, homogeneously illuminated surface, all of the pixel values in the line should be near their maximum gray value and they should be equal. In practice, slight variations in the performance of the pixels in the sensor as well as variations in the optics and in lighting will cause variations in the pixel values output from the camera. PRNU correction corrects for this type of variation. It works by applying an individual multiplier (gain) to each pixel value in the lines acquired.
Shading correction is a pixel-to-pixel calibration method, i.e., a correction value is calculated for each single pixel.
信息
You can set the camera to only perform DSNU correction, to only perform PRNU correction, or to perform both types of shading correction. If you perform both types of shading correction, the camera first performs DSNU correction, then PRNU correction.
Shading Correction Sets#
The correction values used for DSNU and PRNU correction are stored in files referred to as shading correction sets. There are the following two types:
-
Factory correction set: Contains correction values that were stored on the camera during the camera production process. The factory correction set can only reduce image artifacts caused by dark signal non-uniformities (DSNU).
-
User correction set: Contains correction values that must be created by the user and stored on the camera.
Depending on your camera model, you can create up to 32 User correction sets.
Shading Correction Mode#
The shading correction mode determines whether shading correction is based on the values stored in the factory or the user correction set.
To set the shading correction mode, set the BslShadingCorrectionMode
参数设置为以下值:
Factory
(default): Shading correction is based on the values stored in the factory correction set.User
: Shading correction is based on the values stored in the user correction set.熄灭
: The camera does not perform shading corrections.
Creating a Shading Correction Set#
You need the following items before you start creating a user-defined shading correction set:
- An appropriate object to completely cover the lens, e.g., the lens cap
- A target with a uniform background, e.g., a white sheet of paper
信息
- For best results, adjust the optics, line rate, exposure time, gain, and camera temperature as you would for normal operation. Basler recommends acquiring the dark and bright field images in your actual application environment.
- Basler recommends setting the
Width
andHeight
parameters of the image ROI to their maximum values. - racer 2 L cameras: In Dual Line sensor acquisition mode, the status of a shading correction set created in Single Line mode will be indicated as empty (
BslShadingCorrectionSetStatus
= Empty), although correction data already exist in this set.
If you want to create a new shading correction set in Dual Line mode, check the index numbers of your correction sets created in Single Line mode and choose another index number for your new set. Otherwise, the correction data will be overwritten and replaced by the new correction values.
DSNU Correction Set#
To create a shading correction set for DSNU correction:
- Disable Reverse X.
- Prevent any light from hitting the camera’s sensor, e.g., by placing a plastic cap on the lens.
- 设置
BslShadingCorrectionSelector
parameter toDSNU
. - 设置
BslShadingCorrectionMode
parameter toUser
. - 设置
BslShadingCorrectionSetIndex
parameter to the desired index number of the set to be created, e.g., 1. - Click the Continuous Shot button in the toolbar of the pylon Viewer to start image acquisition.
-
Execute the
BslShadingCorrectionSetCreate
command to create a new shading correction set.
A total of 256 dark images are acquired and evaluated. The resulting DSNU correction data are generated, collected in the shading correction set defined, and saved to the camera's flash memory. If the shading correction set with, e.g., index number 1, already contains correction data, these are overwritten and replaced by the new correction values.信息
If a PRNU correction set is enabled while creating DSNU correction data, the PRNU correction values will be ignored for the calculation.
The created shading correction set is enabled automatically.
-
To verify the result of the shading correction set creation, get the value of the
BslShadingCorrectionSetCreateResult
parameter.
PRNU Correction Set#
To create a shading correction set for PRNU correction:
- Disable Reverse X.
- Illuminate the sensor homogeneously to 70 % saturation, e.g., by placing a white sheet of paper in the camera's entire field of view.
- 设置
BslShadingCorrectionSelector
parameter toPRNU
. - 设置
BslShadingCorrectionMode
parameter toUser
. - 设置
BslShadingCorrectionSetIndex
parameter to the desired index number of the set to be created, e.g., 2. - Click the Continuous Shot button in the toolbar of the pylon Viewer to start image acquisition.
-
Execute the
BslShadingCorrectionSetCreate
command to create a new shading correction set.
A total of 256 bright images are acquired and evaluated. The resulting PRNU correction data are generated, collected in the shading correction set selected, and saved to the camera's flash memory. If the shading correction set with, e.g., index number 2, already contains correction data, these are overwritten and replaced by the new correction values.信息
If a DSNU correction set is enabled while creating PRNU correction data, the DSNU correction values are taken into account for the calculation.
The created shading correction set is enabled automatically.
-
To verify the result of the shading correction set creation, get the value of the
BslShadingCorrectionSetCreateResult
parameter. - If required, adjust the target gray value for PRNU correction and repeat step 7.
Adjusting the Target Gray Value for PRNU Correction#
During the creation of a PRNU correction set, the camera detects the maximum brightness value in the bright field image. However, you may want to adjust the relative target gray value of the sensor brightness you want to achieve. Possible reasons for this are, e.g.:
- Your shading correction set can't be created because the correction values are outside the allowed range.
- Bright spots on the image (e.g., caused by light reflections) result in a high maximum brightness value detected by the camera during the creation of the correction set. You may want to reduce this value, which is relevant for calculating the correction data, to improve your correction data.
To adjust the target gray value, set the BslShadingCorrectionTargetValue
parameter to the desired relative target gray value.
信息
- 即:
BslShadingCorrectionTargetValue
parameter is only available when creating PRNU correction sets. - Only pixels with an absolute target gray value lower than the value of the maximum measured value are corrected.
- For racer 2 L cameras operated in Dual Line sensor acquisition mode and racer 2 S color cameras, adjusting the target gray value may show unpredictable results. Use the Single Line mode and a mono pixel format instead.
Further parameters:
BslShadingCorrectionAbsoluteTargetValue
: Absolute target value of the sensor brightness. This is the actual brightness value that has been calculated based on the sensor bit depth of your camera.BslShadingCorrectionMaximumMeasuredValue
: Maximum brightness value detected by the camera during the creation of a PRNU correction set.
Enabling a Shading Correction Set#
To enable a shading correction set:
- 设置
BslShadingCorrectionMode
parameter toUser
, if you want to enable a user-defined correction set, or toFactory
, if you want to enable the factory correction set. -
设置
BslShadingCorrectionSetIndex
parameter to the index number of the set to be used, e.g., index number 2.The shading correction set is enabled automatically.
-
To verify whether this process was successful, get the value of the
BslShadingCorrectionSetStatus
parameter. If the value is确定
, the shading set has been enabled successfully. The camera now performs shading correction based on the correction values in the shading correction set selected.
信息
Changing a shading correction set is possible during image acquisition. However, slight image artifacts may occur during that process.
Disabling Shading Correction#
To disable shading correction, set the BslShadingCorrectionMode
parameter to 熄灭
.
详情#
The following table shows the number of shading sets available for racer 2 cameras.
相机型号 | Max. Number of Lines Exposed per Acquisition | Available Number of Shading Corrections Sets |
---|---|---|
r2L2048-29gc | 3 | 10 |
r2L2048-58gm | 1 | 32 |
r2L2048-62g5c | 3 | 10 |
r2L2048-62cc | 3 | 10 |
r2L2048-172cm | 1 | 32 |
r2L2048-172g5m | 1 | 32 |
r2L4096-14gc | 2 | 16 |
r2L4096-29gm | 1 | 32 |
r2L4096-42cc | 2 | 16 |
r2L4096-42g5c | 2 | 16 |
r2L4096-84cm | 1 | 32 |
r2L4096-84g5m | 1 | 16 |
r2L8192-200cm | 2 | 16 |
r2L16384-120cm | 2 | 16 |
示例代码#
// Set the type of shading correction to DSNU
camera.BslShadingCorrectionSelector.SetValue(BslShadingCorrectionSelector_DSNU);
// Set the shading correction mode to User
camera.BslShadingCorrectionMode.SetValue(BslShadingCorrectionMode_User);
// Set the desired index number of the set to be created
camera.BslShadingCorrectionSetIndex.SetValue(BslShadingCorrectionSetIndex_1);
// Create new shading correction data for the shading correction set selected
camera.BslShadingCorrectionSetCreate.Execute();
// Get the status of the shading correction set selected
BslShadingCorrectionSetStatus setStatus = camera.BslShadingCorrectionSetStatus.GetValue();
INodeMap& nodemap = camera.GetNodeMap();
// Set the type of shading correction to DSNU
CEnumParameter(nodemap, "BslShadingCorrectionSelector").SetValue("DSNU");
// Set the shading correction mode to User
CEnumParameter(nodemap, "BslShadingCorrectionMode").SetValue("User");
// Set the desired index number of the set to be created
CEnumParameter(nodemap, "BslShadingCorrectionSetIndex").SetValue("");
// Create new shading correction data for the shading correction set selected
CCommandParameter(nodemap, "BslShadingCorrectionSetCreate").Execute();
// Get the status of the shading correction set selected
String_t setStatus = CEnumParameter(nodemap, "BslShadingCorrectionSetStatus").GetValue();
// Set the type of shading correction to DSNU
camera.Parameters[PLCamera.BslShadingCorrectionSelector].SetValue(PLCamera.BslShadingCorrectionSelector.DSNU);
// Set the shading correction mode to User
camera.Parameters[PLCamera.BslShadingCorrectionMode].SetValue(PLCamera.BslShadingCorrectionMode.User);
// Set the desired index number of the set to be created
camera.Parameters[PLCamera.BslShadingCorrectionSetIndex].SetValue(PLCamera.BslShadingCorrectionSetIndex.);
// Create new shading correction data for the shading correction set selected
camera.Parameters[PLCamera.BslShadingCorrectionSetCreate].Execute();
// Get the status of the shading correction set selected
string setStatus = camera.Parameters[PLCamera.BslShadingCorrectionSetStatus].GetValue();
/* 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 */
size_t len = 0;
char setStatus_str[64] = {0};
/* Set the type of shading correction to DSNU */
errRes = PylonDeviceFeatureFromString(hdev, "BslShadingCorrectionSelector", "DSNU");
CHECK(errRes);
/* Set the shading correction mode to User */
errRes = PylonDeviceFeatureFromString(hdev, "BslShadingCorrectionMode", "User");
CHECK(errRes);
/* Set the desired index number of the set to be created */
errRes = PylonDeviceFeatureFromString(hdev, "BslShadingCorrectionSetIndex", "");
CHECK(errRes);
/* Create new shading correction data for the shading correction set selected */
errRes = PylonDeviceExecuteCommandFeature(hdev, "BslShadingCorrectionSetCreate");
CHECK(errRes);
/* Get the status of the shading correction set selected */
len = sizeof(setStatus_str);
errRes = PylonDeviceFeatureToString(hdev, "BslShadingCorrectionSetStatus", setStatus_str, &len);
CHECK(errRes);
# Set the type of shading correction to DSNU
camera.BslShadingCorrectionSelector.Value = "DSNU"
# Set the shading correction mode to User
camera.BslShadingCorrectionMode.Value = "User"
# Set the desired index number of the set to be created
camera.BslShadingCorrectionSetIndex.Value = ""
# Create new shading correction data for the shading correction set selected
camera.BslShadingCorrectionSetCreate.Execute()
# Get the status of the shading correction set selected
setStatus = camera.BslShadingCorrectionSetStatus.Value
您也可以使用 pylon Viewer 轻松设置参数。