Defect Pixel Correction#
在采集的图像中,即使使用均匀的光线,部分像素也会显得比其他像素明显更亮或更暗。该问题是由于各个像素的灵敏度差异而引起的,而这些差异又是由于生产公差引起的。
该功能的使用#
该功能的具体实现因相机而异:
ace 2 R/X、boost R 和 dart M 相机#
Basler ace 2 R、ace 2 X、boost R 和 dart M 相机支持 static defect pixel correction。此校正基于存储在相机上且包含坏点坐标列表的文件。
“静态”意味着始终使用相同的指定缺陷像素坐标执行校正过程。在图像采集期间,这些像素的强度值将根据其相邻像素的强度值进行替换。
以下 Defect Pixel Correction 文件可以存储在相机上:
- 工厂文件:包含相机生产过程中检测到的缺陷像素的坐标。
- 用户文件:包含用户定义的坐标。您可以将此文件上传到相机。这允许您定义随着时间的推移可能出现的新缺陷像素。
信息
Basler ace 2 X 相机还支持 dynamic pixel defect correction。有关详细信息,请参阅 Pixel Correction Beyond。
使用 pylon Viewer 校正缺陷像素#
→ 请参阅静态 Defect Pixel Correction (pylon Viewer)。
使用 pylon API 校正缺陷像素#
信息
Basler 建议使用 pylon Viewer 执行 Defect Pixel Correction。
仅当您想要在自己的应用中实现 Defect Pixel Correction 时,才使用 pylon API。
设置静态 Defect Pixel Correction 模式#
若要设置 static defect pixel correction 模式,请将 BslStaticDefectPixelCorrectionMode 参数设置为以下值:
Factory(默认):static defect pixel correction 基于存储在 出厂 校正文件中的坏点。User:static defect pixel correction 基于存储在 用户 校正文件中的坏点。
请注意,通过 pylon API 设置此模式时, 仅 会使用用户定义的像素。当通过 User incl. Factory 设置校正模式时, pylon Viewer除出厂文件中存储的像素外,还将使用用户定义的像素。Off:相机 不 执行 static defect pixel correction。
上传用户 Defect Pixel Correction 文件#
在上传用户 Defect Pixel Correction 文件之前,请确保该文件符合以下文件格式:
文件必须以包含四个值为 0 的字节的 4 字节标题开头。在标题之后,文件必须包含缺陷像素条目(最多可以指定 4096 个缺陷像素)。每个条目由 32 位组成,顺序如下:14 位 y 坐标、14 位 x 坐标、4 位类型
示例:坐标为 x=1 和 y=2 的缺陷像素条目
使用 pylon Viewer 上传用户 Defect Pixel Correction 文件:
- 在 pylon Viewer 的相机菜单中,单击文件访问权限。
- 在相机文件下拉框中,选择用户 Defect Pixel Correction。
如果没有用户 Defect Pixel Correction 条目,您的相机不支持上传校正文件。 - 单击上传并导航到要上传的文件。
- 单击打开。
上传后若要应用 User Defect Pixel Correction 文件,请确保将 BslStaticDefectPixelCorrectionMode 参数设置为 User 并执行 BslStaticDefectPixelCorrectionReload 命令。
下载 Defect Pixel Correction 文件#
如果您想要将自己测量的缺陷像素添加到下载的文件中,下载 Defect Pixel Correction 文件(例如出厂校正文件)可能会很有用。您可以将缺陷像素条目的完整列表存储在新的用户校正文件中。
使用 pylon Viewer 下载 Defect Pixel Correction 文件:
- 在 pylon Viewer 的相机菜单中,单击文件访问权限。
- 在相机文件下拉框中,根据您要下载的文件,选择静态出厂 Defect Pixel Correction 或静态用户 Defect Pixel Correction。
如果没有适当的条目,则您的相机不支持下载文件。 - 单击下载,导航到要保存文件的目录,然后输入所需的文件名。
- 单击打开。
静态 Defect Pixel Correction 文件状态#
即: StaticDefectPixelCorrectionFileStatus 参数可采用以下值:
FileStatusUnknown:坏点校正文件的状态未知。采集一幅图像以更改文件状态。FileOk:坏点校正文件有效。FileNotFound:找不到 Defect Pixel Correction 文件。该文件从未上传或已被删除。FileEmpty:Defect Pixel Correction 文件中没有任何条目。文件头有效,但文件中不包含任何坏点。Defect Pixel Correction 过程已中止。InvalidHeader:Defect Pixel Correction 文件头无效。文件必须具有 4 字节的文件头。InvalidSize:Defect Pixel Correction 文件大小无效。坏点的最大数量不得超过 4096 个。InvalidSorting:Defect Pixel Correction 文件中的条目排序无效。Defect Pixel Correction 过程已中止。InvalidFileEntry:Defect Pixel Correction 文件中至少有一个条目的尺寸无效。Defect Pixel Correction 过程已中止。InvalidClustering:发现无效的簇。连续三个或更多相邻像素被视为无效簇。位于其他坏点之间的任何坏点都无法被校正。
Defect Pixel Correction 文件可以包含的最大坏点数量。若要获取该数量,请获取 BslStaticDefectPixelCorrectionMaxDefects 参数。
boost V 相机#
Basler boost V 相机支持静态 Defect Pixel Correction。此校正基于存储在相机上并包含缺陷像素坐标列表的文件。
“静态”意味着始终使用相同的指定缺陷像素坐标执行校正过程。在图像采集期间,这些像素的强度值将根据其相邻像素的强度值进行替换。
执行 Defect Pixel Correction#
信息
pylon Viewer 的内置静态 Defect Pixel Correction 功能不支持 boost V 相机。
使用 pylon Viewer 或 pylon API 的特征树对 boost V 相机进行 Defect Pixel Correction。
要对 boost V 相机执行 Defect Pixel Correction:
-
设置
BslStaticDefectPixelCorrectionMode参数至所需的校正模式:Factory:仅校正坐标存储在出厂文件中的坏点。出厂文件是在相机生产过程中生成的,无法更改。User:您可以指定自定义坏点坐标。Off:相机 不 执行 static defect pixel correction。
-
如果选择
User:- 找出图像中的像素错误,并记下缺陷像素的 x 和 y 坐标。
- 设置
BslStaticDefectPixelCorrectionYCoordinate参数至 第一个坏点的 y 坐标。 - 设置
BslStaticDefectPixelCorrectionXSelector参数至X0. - 设置
BslStaticDefectPixelCorrectionXCoordinate参数至 x y 坐标。 - 如果还有另一个具有相同 y 坐标但 x 坐标不同的坏点,请将
BslStaticDefectPixelCorrectionXSelector参数设置为下一个条目(例如X1),并输入下一个 x 坐标。 - 对所有其他像素错误重复步骤 b 到 e。
- 执行
BslStaticDefectPixelCorrectionSave命令以将更改保存到 flash memory。
信息
- 您可以使用
BslStaticDefectPixelCorrectionCount参数来检查当前正在校正多少个图像像素。 - 您可以设置
BslStaticDefectPixelCorrectionTestMode参数至On以将所有校正后的像素设置为全白。这有助于在图像中查找正在被校正的像素。
删除缺陷像素坐标#
不能删除出厂文件中的像素坐标。
但是,您可以删除自定义缺陷像素坐标,即在“用户”校正模式下输入的坐标(请参阅上文)。为此:
-
如果要移除单个自定义缺陷像素坐标:
- 设置
BslStaticDefectPixelCorrectionYCoordinate参数至 第一个坏点的 坏点的坐标。 - 设置
BslStaticDefectPixelCorrectionXSelector对应保存坏点 X 坐标条目的参数,例如:X0. - 设置
BslStaticDefectPixelCorrectionXCoordinate参数设为 0xFFFF。 - 执行
BslStaticDefectPixelCorrectionSave命令以将更改保存到 flash memory。
- 设置
-
如果要移除所有自定义缺陷像素坐标:
- 执行
BslStaticDefectPixelCorrectionClearAll命令。这会将所有BslStaticDefectPixelCorrectionXCoordinate参数值设为 0xFFFF。 - 执行
BslStaticDefectPixelCorrectionSave命令以将更改保存到 flash memory。
- 执行
dart 和 pulse 相机#
Basler dart 和 pulse 相机可以执行两种类型的像素校正:
- 静态像素校正用于校正灰度值显著低于相邻像素(包括完全变黑的像素)的像素。
- 动态像素校正用于校正灰度值显著高于相邻像素(包括完全变白的像素)的像素。内部阈值决定了何时将某个像素检测为“热点”。“动态”意味着坏点校正是针对每幅采集到的图像单独计算的。
设置 Defect Pixel Correction 模式#
若要设置 Defect Pixel Correction 模式,请将 BslDefectPixelCorrectionMode 参数设置为以下值:
On(默认):相机执行 静态和动态 像素校正。StaticOnly:相机仅执行 静态 像素校正。Off:相机 不 执行像素校正。
示例代码#
ace 2 R/X、boost R 和 dart M 相机#
/* 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 */
/* Set static user defect pixel correction */
errRes = PylonDeviceFeatureFromString(hdev, "BslStaticDefectPixelCorrectionMode", "User");
CHECK(errRes);
/* Reload static defect pixel correction file */
errRes = PylonDeviceExecuteCommandFeature(hdev, "BslStaticDefectPixelCorrectionReload");
CHECK(errRes);
boost V 相机#
// Set the defect pixel correction mode to User
camera.BslStaticDefectPixelCorrectionMode.SetValue(BslStaticDefectPixelCorrectionMode_User);
// Assume there are two defect pixels at coordinates (120,430) and (182,430)
// Set the y coordinate to 430
camera.BslStaticDefectPixelCorrectionYCoordinate.SetValue(430);
// Select entry X0 and assign the first x coordinate
camera.BslStaticDefectPixelCorrectionXSelector.SetValue(BslStaticDefectPixelCorrectionXSelector_X0);
camera.BslStaticDefectPixelCorrectionXCoordinate.SetValue(120);
// Select entry X1 and assign the second x coordinate, which is in the same line
camera.BslStaticDefectPixelCorrectionXSelector.SetValue(BslStaticDefectPixelCorrectionXSelector_X1);
camera.BslStaticDefectPixelCorrectionXCoordinate.SetValue(182);
// Save changes to flash memory
camera.BslStaticDefectPixelCorrectionSave.Execute();
INodeMap& nodemap = camera.GetNodeMap();
// Set the defect pixel correction mode to User
CEnumParameter(nodemap, "BslStaticDefectPixelCorrectionMode").SetValue("User");
// Assume there are two defect pixels at coordinates (120,430) and (182,430)
// Set the y coordinate to 430
CIntegerParameter(nodemap, "BslStaticDefectPixelCorrectionYCoordinate").SetValue(430);
// Select entry X0 and assign the first x coordinate
CEnumParameter(nodemap, "BslStaticDefectPixelCorrectionXSelector").SetValue("X0");
CIntegerParameter(nodemap, "BslStaticDefectPixelCorrectionXCoordinate").SetValue(120);
// Select entry X1 and assign the second x coordinate, which is in the same line
CEnumParameter(nodemap, "BslStaticDefectPixelCorrectionXSelector").SetValue("X1");
CIntegerParameter(nodemap, "BslStaticDefectPixelCorrectionXCoordinate").SetValue(182);
// Save changes to flash memory
CCommandParameter(nodemap, "BslStaticDefectPixelCorrectionSave").Execute();
// Set the defect pixel correction mode to User
camera.Parameters[PLCamera.BslStaticDefectPixelCorrectionMode].SetValue(PLCamera.BslStaticDefectPixelCorrectionMode.User);
// Assume there are two defect pixels at coordinates (120,430) and (182,430)
// Set the y coordinate to 430
camera.Parameters[PLCamera.BslStaticDefectPixelCorrectionYCoordinate].SetValue(430);
// Select entry X0 and assign the first x coordinate
camera.Parameters[PLCamera.BslStaticDefectPixelCorrectionXSelector].SetValue(PLCamera.BslStaticDefectPixelCorrectionXSelector.X0);
camera.Parameters[PLCamera.BslStaticDefectPixelCorrectionXCoordinate].SetValue(120);
// Select entry X1 and assign the second x coordinate, which is in the same line
camera.Parameters[PLCamera.BslStaticDefectPixelCorrectionXSelector].SetValue(PLCamera.BslStaticDefectPixelCorrectionXSelector.X1);
camera.Parameters[PLCamera.BslStaticDefectPixelCorrectionXCoordinate].SetValue(182);
// Save changes to flash memory
camera.Parameters[PLCamera.BslStaticDefectPixelCorrectionSave].Execute();
/* 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 */
/* Set the defect pixel correction mode to User */
errRes = PylonDeviceFeatureFromString(hdev, "BslStaticDefectPixelCorrectionMode", "User");
CHECK(errRes);
/* Assume there are two defect pixels at coordinates (120,430) and (182,430) */
/* Set the y coordinate to 430 */
errRes = PylonDeviceSetIntegerFeature(hdev, "BslStaticDefectPixelCorrectionYCoordinate", 430);
CHECK(errRes);
/* Select entry X0 and assign the first x coordinate */
errRes = PylonDeviceFeatureFromString(hdev, "BslStaticDefectPixelCorrectionXSelector", "X0");
CHECK(errRes);
errRes = PylonDeviceSetIntegerFeature(hdev, "BslStaticDefectPixelCorrectionXCoordinate", 120);
CHECK(errRes);
/* Select entry X1 and assign the second x coordinate, which is in the same line */
errRes = PylonDeviceFeatureFromString(hdev, "BslStaticDefectPixelCorrectionXSelector", "X1");
CHECK(errRes);
errRes = PylonDeviceSetIntegerFeature(hdev, "BslStaticDefectPixelCorrectionXCoordinate", 182);
CHECK(errRes);
/* Save changes to flash memory */
errRes = PylonDeviceExecuteCommandFeature(hdev, "BslStaticDefectPixelCorrectionSave");
CHECK(errRes);
# Set the defect pixel correction mode to User
camera.BslStaticDefectPixelCorrectionMode.Value = "User"
# Assume there are two defect pixels at coordinates (120,430) and (182,430)
# Set the y coordinate to 430
camera.BslStaticDefectPixelCorrectionYCoordinate.Value = 430
# Select entry X0 and assign the first x coordinate
camera.BslStaticDefectPixelCorrectionXSelector.Value = "X0"
camera.BslStaticDefectPixelCorrectionXCoordinate.Value = 120
# Select entry X1 and assign the second x coordinate, which is in the same line
camera.BslStaticDefectPixelCorrectionXSelector.Value = "X1"
camera.BslStaticDefectPixelCorrectionXCoordinate.Value = 182
# Save changes to flash memory
camera.BslStaticDefectPixelCorrectionSave.Execute()
dart 和 pulse 相机#
/* 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 */
/* Disable defect pixel correction */
errRes = PylonDeviceFeatureFromString(hdev, "DefectPixelCorrectionMode", "Off");
CHECK(errRes);
您也可以使用 pylon Viewer 轻松设置参数。