跳转到内容
暂存服务器
开发服务器

Shading Correction#

使用 Shading Correction 相机功能可以减少由传感器像素光敏感度差异引起的图像不均匀现象。此外,还可以最大限度地减少由照明和照明光学器件引起的伪像。

Shading correction 基于存储在相机上并包含相应矫正数据的档案。在图像采集过程中,这些档案将应用于原始像素值,从而改善图像。

Shading Correction 功能仅适用于 racer 2 相机。

该功能的使用#

运作原理#

DSNU 和 PRNU Correction#

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) 引起的图像伪像。

  • 用户矫正设置:包含必须由用户创建并存储在相机上的矫正值。根据您的相机型号,您最多可以创建 32 个用户矫正设置。

    您可以下载或上传用户 shading correction 文件。

下载 Shading Correction 文件#

信息

  • 下载您的 shading correction 文件有助于备份矫正数据。
  • Basler 强烈建议在执行固件更新之前备份您的矫正文件。
  • 请勿编辑已下载的 shading correction 文件。

要使用 pylon Viewer 下载 Shading Correction 文件:

  1. 在 pylon Viewer 中,打开要从中下载 Shading Correction 数据文件的相机。
  2. 在 pylon Viewer 的相机菜单中,单击文件访问权限。
  3. 在 Camera File 下拉框中,根据要下载的文件选择 PRNU Correction 或 DSNU Correction。
    如果没有相应的条目,则说明您的相机不支持下载 Shading Correction 文件。
  4. 单击下载,导航到要保存文件的目录,然后输入所需的文件名。
  5. 点击 Save。
  6. 关闭 Camera File Access 对话框。

上传 Shading Correction 文件#

信息

  • 如果您将用户 Shading Correction 文件上传到相机,请确保所选的校正集是在您加载校正数据的相机上创建的。
  • Basler 强烈建议不要上传经过编辑的用户 Shading Correction 文件。

要使用 pylon Viewer 上传用户 Shading Correction 文件:

  1. 在 pylon Viewer 中,打开要将 Shading Correction 数据文件上传到的相机。
  2. 在 pylon Viewer 的相机菜单中,单击文件访问权限。
  3. 在 Camera File 下拉框中,选择 PRNU Correction 或 DSNU Correction。
    如果没有 PRNU Correction 或 DSNU Correction 条目,则说明您的相机不支持上传校正文件。
  4. 单击上传并导航到要上传的文件。
  5. 单击打开。
  6. 关闭 Camera File Access 对话框。

要在上传后应用 Shading Correction 文件,请确保 BslShadingCorrectionMode 参数设置为 User 和 BslShadingCorrectionSetIndex 参数设置为相应的索引号。

Shading Correction 模式#

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 = 空),尽管该集中已存在校正数据。
    如果您想在 Dual 或 Quad Line 模式下创建新的 Shading Correction 集,请检查在行数较少的模式下创建的校正集的索引号。如果某个索引号已被占用,请为新集选择其他数字。否则,校正数据将被新校正值覆盖并替换。

DSNU Correction Set#

要为 DSNU correction 创建 Shading Correction 集,请执行以下操作:

  1. 防止任何光线照射到相机传感器上,例如通过在镜头上放置塑料盖。
  2. 设置 BslShadingCorrectionSelector 将参数设置为 DSNU.
  3. 设置 BslShadingCorrectionMode 将参数设置为 User.
  4. 设置 BslShadingCorrectionSetIndex 参数设置为要创建的集的所需索引号,例如 1。
  5. 设置 BslShadingCorrectionROISelector 参数设置为所需的 Shading Correction ROI,例如 ROI 1。
  6. 如果需要,可以使用以下参数设置 Shading Correction ROI 的位置和大小:
    • BslShadingCorrectionROIOffsetX:Shading Correction ROI 距传感器左侧的水平偏移量(以像素为单位)。
    • BslShadingCorrectionROIWidth:Shading Correction ROI 的宽度(以像素为单位)。
  7. 单击 pylon Viewer 工具栏中的 Continuous Shot 按钮以开始图像采集。
  8. 执行 BslShadingCorrectionSetCreate 命令以创建新的 Shading Correction 集。
    总共采集并评估 256 张暗图像。生成相应的 DSNU 校正数据,将其收集到定义的 Shading Correction 集并保存到相机的闪存中。如果例如索引号为 1 的 Shading Correction 集已包含校正数据,这些数据将被新校正值覆盖并替换。

    信息

    如果在创建 DSNU 校正数据时启用了 PRNU correction 集,计算时将忽略 PRNU 校正值。

    创建的 Shading Correction 集将自动启用。

  9. 要验证 Shading Correction 集创建的结果,请获取 BslShadingCorrectionSetCreateResult 参数。

PRNU Correction Set#

要为 PRNU correction 创建 Shading Correction 集,请执行以下操作:

  1. 将传感器均匀照明至 70% 的饱和度,例如通过在相机的整个视野中放置一张白纸。
  2. 设置 BslShadingCorrectionSelector 将参数设置为 PRNU.
  3. 设置 BslShadingCorrectionMode 将参数设置为 User.
  4. 设置 BslShadingCorrectionSetIndex 参数设置为要创建的集的所需索引号,例如 2。
  5. 设置 BslShadingCorrectionROISelector 参数设置为所需的 Shading Correction ROI,例如 ROI 1。
  6. 如果需要,可以使用以下参数设置 Shading Correction ROI 的位置和大小:
    • BslShadingCorrectionROIOffsetX:Shading Correction ROI 距传感器左侧的水平偏移量(以像素为单位)。
    • BslShadingCorrectionROIWidth:Shading Correction ROI 的宽度(以像素为单位)。
  7. 单击 pylon Viewer 工具栏中的 Continuous Shot 按钮以开始图像采集。
  8. 执行 BslShadingCorrectionSetCreate 命令以创建新的 Shading Correction 集。
    总共采集并评估 256 张亮图像。生成相应的 PRNU 校正数据,将其收集到所选的 Shading Correction 集并保存到相机的闪存中。如果例如索引号为 2 的 Shading Correction 集已包含校正数据,这些数据将被新校正值覆盖并替换。

    信息

    如果在创建 PRNU 校正数据时启用了 DSNU correction 集,计算时将考虑 DSNU 校正值。

    创建的 Shading Correction 集将自动启用。

  9. 要验证 Shading Correction 集创建的结果,请获取 BslShadingCorrectionSetCreateResult 参数。

  10. 如果需要,调整 目标灰度值用于 PRNU correction 并重复步骤 7。如果您使用的是彩色相机,请分别为每个颜色通道调整用于 PRNU correction 的目标灰度值,并重复步骤 7。

调整 PRNU 矫正的目标灰度值#

在 创建 PRNU correction 集期间,相机检测亮场图像中的最大亮度值。但是,您可能需要调整要达到的传感器亮度的相对目标灰度值。这样做的可能原因例如有:

  • 无法创建您的 Shading Correction 集,因为校正值超出了允许的范围。
  • 图像上的亮点(例如由光线反射引起)会导致相机在创建校正集期间检测到较高的最大亮度值。您可能需要降低该值(该值与计算校正数据相关),以改善校正数据。

若要调整用于 PRNU 校正的目标灰度值:

  1. 设置 BslShadingCorrectionTargetSelector 参数设置为以下值:
    • All (仅限单色相机):目标灰度值应用于所有传感器行。
    • Red, Green, Blue (仅限彩色相机):目标灰度值应用于各自的颜色通道。
  2. 设置 BslShadingCorrectionTargetValue 参数设置为所需的目标相对灰度值。
  3. 如果您使用的是彩色相机,请重复步骤 1 和 2,将所需的目标灰度值应用到其他颜色通道。

信息

  • 即: BslShadingCorrectionTargetValue 参数仅可在以下情况下使用: 创建 PRNU 校正集.
  • 仅对绝对目标灰度值低于最大测量值的像素进行校正。
  • 对于在 Dual 或 Quad Line Sensor Acquisition Mode 下运行的 racer 2 L 相机,调整目标灰度值可能会产生不可预测的结果。请改用 Single Line 模式和单色 Pixel Format。

其他参数:

  • BslShadingCorrectionAbsoluteTargetValue:传感器的绝对目标亮度值。这是根据相机的 Sensor Bit Depth 计算出的实际亮度值。
  • BslShadingCorrectionMaximumMeasuredValue:相机在 创建 PRNU 校正集.

启用 Shading Correction 设置#

若要启用 Shading Correction 集:

  1. 设置 BslShadingCorrectionMode 将参数设置为 User,如果您想启用用户定义的校正集,或者 Factory,如果您想启用出厂校正集。
  2. 设置 BslShadingCorrectionSetIndex 参数设置为要使用的集的索引号,例如索引号 2。

    Shading Correction 集会自动启用。

  3. 若要验证此过程是否成功,请获取 BslShadingCorrectionSetStatus 参数的值。如果该值为 Ok,则说明 Shading 集已成功启用。相机现在会根据所选 Shading Correction 集中的校正值执行 Shading Correction。

信息

可以在图像采集期间更改 Shading Correction 集。但是,在此过程中可能会出现轻微的图像伪影。

禁用 Shading Correction#

若要禁用 Shading Correction,请将 BslShadingCorrectionMode 将参数设置为 Off.

详情#

下表显示了 racer 2 相机可用的 Shading Correction 集数量。

相机型号 每次采集的最大曝光行数 可用的 Shading Correction 集数量
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 轻松设置参数。