Shading Correction#
Shading correction 基于存储在相机上且包含相应矫正数据的档案。在图像采集过程中,这些数据将应用于原始像素值,从而改善图像。
Shading Correction 功能仅适用于 racer 2 相机。
该功能的使用#
运作原理#
DSNU 和 PRNU 校正#
Shading correction 可最大程度地减少由暗电流非均匀性 (DSNU)和光响应非均匀性 (PRNU)引起的图像伪影。相机提供以下两种类型的 shading correction:
-
DSNU 矫正:当相机在完全黑暗的环境中捕获行时,行中的所有像素值应接近于零且应当相等。在实际操作中,当相机在黑暗中捕获行时,传感器像素性能的微小变化会导致相机输出的像素值产生一些变化。DSNU 矫正可矫正此类变化。它的工作原理是向采集的行中的每个像素值添加一个单独的灰度值(偏移量)。
-
PRNU 矫正:当相机对准明亮且均匀照明的表面捕获行时,行中的所有像素值应接近其最大灰度值且应当相等。在实际操作中,传感器像素性能的微小变化以及光学器件和照明的变化会导致相机输出的像素值发生变化。PRNU 矫正可矫正此类变化。它的工作原理是向采集的行中的每个像素值应用单独的乘数(增益)。
Shading correction 是一种像素到像素的校准方法,即为每个单独的像素计算矫正值。
信息
您可以将相机设置为仅执行 DSNU 矫正、仅执行 PRNU 矫正或同时执行这两种 shading correction。如果您同时执行这两种 shading correction,相机将首先执行 DSNU 矫正,然后执行 PRNU 矫正。
Shading Correction 集#
用于 DSNU 和 PRNU 矫正的矫正值存储在称为 shading correction 集的文件中。主要有以下两种类型:
-
工厂矫正集:包含在相机生产过程中存储在相机上的矫正值。工厂矫正集只能减少由暗电流非均匀性 (DSNU) 引起的图像伪影。
下载 Shading Correction 文件#
信息
- 下载 shading correction 文件有助于备份矫正数据。
- Basler 强烈建议在执行固件更新之前备份矫正文件。
- 请勿编辑已下载的 shading correction 文件。
若要使用 pylon Viewer 下载 shading correction 文件:
- 在 pylon Viewer 中,打开要从中下载 shading correction 数据文件的相机。
- 在 pylon Viewer 的相机菜单中,单击文件访问权限。
- 在 Camera File 下拉框中,根据要下载的文件选择 PRNU Correction 或 DSNU Correction。
如果没有相应的条目,则表示您的相机不支持下载 shading correction 文件。 - 单击下载,导航到要保存文件的目录,然后输入所需的文件名。
- 点击 Save。
- 关闭 Camera File Access 对话框。
上传 Shading Correction 文件#
信息
- 如果您要将用户 Shading Correction 文件上传到相机,请确保所选的校正集是在您要加载校正数据的相机上创建的。
- Basler 强烈建议不要上传经过编辑的用户 Shading Correction 文件。
要使用 pylon Viewer 上传用户 Shading Correction 文件:
- 在 pylon Viewer 中,打开要将 Shading Correction 数据文件上传到的相机。
- 在 pylon Viewer 的相机菜单中,单击文件访问权限。
- 在 Camera File 下拉框中,选择 PRNU Correction 或 DSNU Correction。
如果没有 PRNU Correction 或 DSNU Correction 条目,则说明您的相机不支持上传校正文件。 - 单击上传并导航到要上传的文件。
- 单击打开。
- 关闭 Camera File Access 对话框。
要在上传后应用 Shading Correction 文件,请确保 BslShadingCorrectionMode 参数设置为 User 和 BslShadingCorrectionSetIndex 参数已设置为相应的索引号。
Shading Correction Mode#
Shading Correction 模式决定了 Shading Correction 是基于出厂存储的值还是基于用户校正集。
要设置 Shading Correction 模式,请将 BslShadingCorrectionMode 参数设置为以下值:
Factory(默认):Shading Correction 基于存储在 出厂 校正集中的值。User:Shading Correction 基于存储在 用户 校正集中的值。Off:相机 不 执行 Shading Correction。
创建 Shading Correction 集#
在开始创建用户自定义 Shading Correction 集之前,您需要准备好以下物品:
- 完全盖住镜头的合适物体,例如镜头盖
- 具有均匀背景的目标,例如一张白纸
信息
- 为获得最佳结果,请像在正常操作中一样调整光学元件、行频、Exposure Time、增益和相机温度。Basler 建议在您的实际应用环境中采集暗场和明场图像。
- racer 2 L 相机:在 Dual(或 Quad)Line 传感器采集模式中,在 Single(或 Dual)Line 模式下创建的 Shading Correction 集的状态将显示为空(
BslShadingCorrectionSetStatus= Empty),尽管此集中已存在校正数据。
如果您想在 Dual 或 Quad Line 模式下创建新的 Shading Correction 集,请检查在行数较少的模式下创建的校正集的索引号。如果某个索引号已被占用,请为您的新集选择其他编号。否则,原有的校正数据将被新的校正值覆盖和替换。
DSNU Correction Set#
要为 DSNU correction 创建 Shading Correction 集:
- 防止任何光线照射到相机的传感器上,例如在镜头上放置塑料盖。
- 设置
BslShadingCorrectionSelector参数至DSNU. - 设置
BslShadingCorrectionMode参数至User. - 设置
BslShadingCorrectionSetIndex参数设置为要创建的集的所需索引号,例如 1。 - 设置
BslShadingCorrectionROISelector参数设置为所需的 Shading Correction ROI,例如 ROI 1。 - 如果需要,请使用以下参数设置 Shading Correction ROI 的位置和大小:
BslShadingCorrectionROIOffsetX:Shading Correction ROI 距传感器左侧的水平偏移量(以像素为单位)。BslShadingCorrectionROIWidth:Shading Correction ROI 的宽度(以像素为单位)。
- 点击 pylon Viewer 工具栏中的 Continuous Shot 按钮以开始图像采集。
-
执行
BslShadingCorrectionSetCreate用于创建新的 shading correction set 的命令。
总共采集并评估 256 张暗场图像。系统会生成相应的 DSNU 校正数据,将其收集到指定的 shading correction set 中,并保存到相机的闪存中。如果例如索引号为 1 的 shading correction set 已经包含校正 data,这些数据将被新的校正值覆盖和替换。信息
如果在创建 DSNU 校正数据时启用了 PRNU correction set,则在计算时将忽略 PRNU 校正值。
创建的 shading correction set 将自动启用。
-
若要验证 shading correction set 创建的结果,请获取以下参数的值:
BslShadingCorrectionSetCreateResult参数。
PRNU Correction Set#
若要为 PRNU correction 创建 shading correction set:
- 使传感器均匀受光至 70% 的饱和度,例如,将一张白纸放置在相机的整个视野中。
- 设置
BslShadingCorrectionSelector参数至PRNU. - 设置
BslShadingCorrectionMode参数至User. - 设置
BslShadingCorrectionSetIndex参数为要创建的集合的所需索引号,例如 2。 - 设置
BslShadingCorrectionROISelector参数设置为所需的 Shading Correction ROI,例如 ROI 1。 - 如果需要,请使用以下参数设置 Shading Correction ROI 的位置和大小:
BslShadingCorrectionROIOffsetX:Shading Correction ROI 距传感器左侧的水平偏移量(以像素为单位)。BslShadingCorrectionROIWidth:Shading Correction ROI 的宽度(以像素为单位)。
- 点击 pylon Viewer 工具栏中的 Continuous Shot 按钮以开始图像采集。
-
执行
BslShadingCorrectionSetCreate用于创建新的 shading correction set 的命令。
总共采集并评估 256 张亮场图像。系统会生成相应的 PRNU 校正数据,将其收集到所选的 shading correction set 中,并保存到相机的闪存中。如果例如索引号为 2 的 shading correction set 已经包含校正 data,这些数据将被新的校正值覆盖和替换。信息
如果在创建 PRNU 校正数据时启用了 DSNU correction set,则在计算时会考虑 DSNU 校正值。
创建的 shading correction set 将自动启用。
-
若要验证 shading correction set 创建的结果,请获取以下参数的值:
BslShadingCorrectionSetCreateResult参数。 - 如果需要,请调整 target gray value for PRNU correction 并重复步骤 7。如果您使用的是彩色相机,请分别针对每个彩色通道调整 target gray value for PRNU correction,并重复步骤 7。
调整 PRNU 矫正的目标灰度值#
在创建 PRNU correction set 期间,相机检测亮场图像中的最大亮度值。但是,您可能希望调整您要实现的传感器亮度的相对目标灰度值。可能的原因为:
- 无法创建 shading correction set,因为校正值超出了允许的范围。
- 图像上的亮点(例如由光线反射引起)会导致相机在创建校正集期间检测到较高的最大亮度值。您可能希望减小此值(该值与计算校正数据相关),以改善校正数据。
若要调整 target gray value for PRNU correction:
- 设置
BslShadingCorrectionTargetSelector参数设置为以下值:All(仅限单色相机):目标灰度值应用于所有传感器行。Red,Green,Blue(仅限彩色相机):目标灰度值应用于各自的彩色通道。
- 设置
BslShadingCorrectionTargetValue参数设置为所需的相对目标灰度值。 - 如果您使用的是彩色相机,请重复步骤 1 和 2,将所需的 target gray value 应用到其他彩色通道。
信息
- 即:
BslShadingCorrectionTargetValue参数只能在 创建 PRNU correction sets. - 仅对绝对目标灰度值低于最大测得值的像素进行校正。
- 对于在 Dual 或 Quad Line Sensor Acquisition Mode 下运行的 racer 2 L 相机,调整 target gray value 可能会产生不可预测的结果。请改用 Single Line 模式和单色 Pixel Format。
更多参数:
BslShadingCorrectionAbsoluteTargetValue: 传感器亮度的绝对目标值。这是根据您相机的 Sensor Bit Depth 计算出的实际亮度值。BslShadingCorrectionMaximumMeasuredValue: 相机在 创建 PRNU 矫正集期间检测到的最大亮度值.
启用 Shading Correction 集#
要启用 Shading Correction 集:
- 设置
BslShadingCorrectionMode参数至User,如果您想启用用户定义的矫正集,或者Factory,如果您想启用出厂矫正集。 -
设置
BslShadingCorrectionSetIndex参数设置为要使用的集的索引号,例如索引号 2。Shading Correction 集会自动启用。
-
要验证此过程是否成功,请获取
BslShadingCorrectionSetStatus参数的值。如果该值为Ok,则说明阴影集已成功启用。现在,相机将根据所选 Shading Correction 集中的矫正值执行 Shading Correction。
信息
在图像采集过程中可以更改 Shading Correction 集。但是,在此过程中可能会出现轻微的图像伪影。
禁用 Shading Correction#
要禁用 Shading Correction,请设置 BslShadingCorrectionMode 参数至 Off.
详情#
下表显示了适用于 racer 2 相机的 Shading Correction 集数量。
| 相机型号 | 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-80cc | 3 | 10 |
| r2L8192-240cm | 4 | 8 |
| r2L16384-60cc | 2 | 16 |
| r2L16384-120cm | 2 | 16 |
| r2T16416-500cm | 1 | 32 |
示例代码#
// Set the type of shading correction to DSNU
camera.BslShadingCorrectionSelector.SetValue(BslShadingCorrectionSelector_DSNU);
// Or for PRNU: Set the type of shading correction to PRNU
camera.BslShadingCorrectionSelector.SetValue(BslShadingCorrectionSelector_PRNU);
// Note: Valid for DSNU and PRNU:
// 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(1);
// Set the shading correction ROI selector to ROI 1
camera.BslShadingCorrectionROISelector.SetValue(BslShadingCorrectionROISelector_ROI1);
// Set the offset X of the ROI to 0
camera.BslShadingCorrectionROIOffsetX.SetValue(0);
// Set the ROI width to 2048
camera.BslShadingCorrectionROIWidth.SetValue(2048);
// Note: Valid for PRNU only:
// Set the shading correction target selector to red
camera.BslShadingCorrectionTargetSelector.SetValue(BslShadingCorrectionTargetSelector_Red);
// Set the shading correction target value for red to 1000
camera.BslShadingCorrectionTargetValue.SetValue(1.0000);
// Set the shading correction target selector to green
camera.BslShadingCorrectionTargetSelector.SetValue(BslShadingCorrectionTargetSelector_Green);
// Set the shading correction target value for green to 1000
camera.BslShadingCorrectionTargetValue.SetValue(1.0000);
// Set the shading correction target selector to blue
camera.BslShadingCorrectionTargetSelector.SetValue(BslShadingCorrectionTargetSelector_Blue);
// Set the shading correction target value for blue to 1000
camera.BslShadingCorrectionTargetValue.SetValue(1.0000);
// Note: Valid for DSNU and PRNU:
// 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");
// Or for PRNU: Set the type of shading correction to PRNU
CEnumParameter(nodemap, "BslShadingCorrectionSelector").SetValue("PRNU");
// Note: Valid for DSNU and PRNU:
// Set the shading correction mode to User
CEnumParameter(nodemap, "BslShadingCorrectionMode").SetValue("User");
// Set the desired index number of the set to be created
CIntegerParameter(nodemap, "BslShadingCorrectionSetIndex").SetValue(1);
// Set the shading correction ROI selector to ROI 1
CEnumParameter(nodemap, "BslShadingCorrectionROISelector").SetValue("ROI1");
// Set the offset X of the ROI to 0
CIntegerParameter(nodemap, "BslShadingCorrectionROIOffsetX").SetValue(0);
// Set the ROI width to 2048
CIntegerParameter(nodemap, "BslShadingCorrectionROIWidth").SetValue(2048);
// Note: Valid for PRNU only:
// Set the shading correction target selector to red
CEnumParameter(nodemap, "BslShadingCorrectionTargetSelector").SetValue("Red");
// Set the shading correction target value for red to 1000
CFloatParameter(nodemap, "BslShadingCorrectionTargetValue").SetValue(1.0000);
// Set the shading correction target selector to green
CEnumParameter(nodemap, "BslShadingCorrectionTargetSelector").SetValue("Green");
// Set the shading correction target value for green to 1000
CFloatParameter(nodemap, "BslShadingCorrectionTargetValue").SetValue(1.0000);
// Set the shading correction target selector to blue
CEnumParameter(nodemap, "BslShadingCorrectionTargetSelector").SetValue("Blue");
// Set the shading correction target value for blue to 1000
CFloatParameter(nodemap, "BslShadingCorrectionTargetValue").SetValue(1.0000);
// Note: Valid for DSNU and PRNU:
// 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);
// Or for PRNU: Set the type of shading correction to PRNU
camera.Parameters[PLCamera.BslShadingCorrectionSelector].SetValue(PLCamera.BslShadingCorrectionSelector.PRNU);
// Note: Valid for DSNU and PRNU:
// 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(1);
// Set the shading correction ROI selector to ROI 1
camera.Parameters[PLCamera.BslShadingCorrectionROISelector].SetValue(PLCamera.BslShadingCorrectionROISelector.ROI1);
// Set the offset X of the ROI to 0
camera.Parameters[PLCamera.BslShadingCorrectionROIOffsetX].SetValue(0);
// Set the ROI width to 2048
camera.Parameters[PLCamera.BslShadingCorrectionROIWidth].SetValue(2048);
// Note: Valid for PRNU only:
// Set the shading correction target selector to red
camera.Parameters[PLCamera.BslShadingCorrectionTargetSelector].SetValue(PLCamera.BslShadingCorrectionTargetSelector.Red);
// Set the shading correction target value for red to 1000
camera.Parameters[PLCamera.BslShadingCorrectionTargetValue].SetValue(1.0000);
// Set the shading correction target selector to green
camera.Parameters[PLCamera.BslShadingCorrectionTargetSelector].SetValue(PLCamera.BslShadingCorrectionTargetSelector.Green);
// Set the shading correction target value for green to 1000
camera.Parameters[PLCamera.BslShadingCorrectionTargetValue].SetValue(1.0000);
// Set the shading correction target selector to blue
camera.Parameters[PLCamera.BslShadingCorrectionTargetSelector].SetValue(PLCamera.BslShadingCorrectionTargetSelector.Blue);
// Set the shading correction target value for blue to 1000
camera.Parameters[PLCamera.BslShadingCorrectionTargetValue].SetValue(1.0000);
// Note: Valid for DSNU and PRNU:
// 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);
/* Or for PRNU: Set the type of shading correction to PRNU */
errRes = PylonDeviceFeatureFromString(hdev, "BslShadingCorrectionSelector", "PRNU");
CHECK(errRes);
/* Note: Valid for DSNU and PRNU: */
/* 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 = PylonDeviceSetIntegerFeature(hdev, "BslShadingCorrectionSetIndex", 1);
CHECK(errRes);
/* Set the shading correction ROI selector to ROI 1 */
errRes = PylonDeviceFeatureFromString(hdev, "BslShadingCorrectionROISelector", "ROI1");
CHECK(errRes);
/* Set the offset X of the ROI to 0 */
errRes = PylonDeviceSetIntegerFeature(hdev, "BslShadingCorrectionROIOffsetX", 0);
CHECK(errRes);
/* Set the ROI width to 2048 */
errRes = PylonDeviceSetIntegerFeature(hdev, "BslShadingCorrectionROIWidth", 2048);
CHECK(errRes);
/* Note: Valid for PRNU only: */
/* Set the shading correction target selector to red */
errRes = PylonDeviceFeatureFromString(hdev, "BslShadingCorrectionTargetSelector", "Red");
CHECK(errRes);
/* Set the shading correction target value for red to 1000 */
errRes = PylonDeviceSetFloatFeature(hdev, "BslShadingCorrectionTargetValue", 1.0000);
CHECK(errRes);
/* Set the shading correction target selector to green */
errRes = PylonDeviceFeatureFromString(hdev, "BslShadingCorrectionTargetSelector", "Green");
CHECK(errRes);
/* Set the shading correction target value for green to 1000 */
errRes = PylonDeviceSetFloatFeature(hdev, "BslShadingCorrectionTargetValue", 1.0000);
CHECK(errRes);
/* Set the shading correction target selector to blue */
errRes = PylonDeviceFeatureFromString(hdev, "BslShadingCorrectionTargetSelector", "Blue");
CHECK(errRes);
/* Set the shading correction target value for blue to 1000 */
errRes = PylonDeviceSetFloatFeature(hdev, "BslShadingCorrectionTargetValue", 1.0000);
CHECK(errRes);
/* Note: Valid for DSNU and PRNU: */
/* 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"
# Or for PRNU: Set the type of shading correction to PRNU
camera.BslShadingCorrectionSelector.Value = "PRNU"
# Note: Valid for DSNU and PRNU:
# 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 = 1
# Set the shading correction ROI selector to ROI 1
camera.BslShadingCorrectionROISelector.Value = "ROI1"
# Set the offset X of the ROI to 0
camera.BslShadingCorrectionROIOffsetX.Value = 0
# Set the ROI width to 2048
camera.BslShadingCorrectionROIWidth.Value = 2048
# Note: Valid for PRNU only:
# Set the shading correction target selector to red
camera.BslShadingCorrectionTargetSelector.Value = "Red"
# Set the shading correction target value for red to 1000
camera.BslShadingCorrectionTargetValue.Value = 1.0000
# Set the shading correction target selector to green
camera.BslShadingCorrectionTargetSelector.Value = "Green"
# Set the shading correction target value for green to 1000
camera.BslShadingCorrectionTargetValue.Value = 1.0000
# Set the shading correction target selector to blue
camera.BslShadingCorrectionTargetSelector.Value = "Blue"
# Set the shading correction target value for blue to 1000
camera.BslShadingCorrectionTargetValue.Value = 1.0000
# Note: Valid for DSNU and PRNU:
# 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 轻松设置参数。