Defect Pixel Correction#
在采集的图像中,即使使用均匀的光线,部分像素也会显得比其他像素明显更亮或更暗。该问题是由于各个像素的灵敏度差异而引起的,而这些差异又是由于生产公差引起的。
该功能的使用#
The implementation of this feature varies depending on the camera:
ace 2 R/X, boost R, and dart M Cameras#
Basler ace 2 R, ace 2 X, boost R, and dart M cameras support static defect pixel correction. This correction is based on files that are stored on the camera and contain a list of defect pixel coordinates.
“静态”意味着始终使用相同的指定缺陷像素坐标执行校正过程。在图像采集期间,这些像素的强度值将根据其相邻像素的强度值进行替换。
以下 Defect Pixel Correction 文件可以存储在相机上:
- 工厂文件:包含相机生产过程中检测到的缺陷像素的坐标。
- 用户文件:包含用户定义的坐标。您可以将此文件上传到相机。这允许您定义随着时间的推移可能出现的新缺陷像素。
信息
Basler ace 2 X cameras also support dynamic pixel defect correction. For more information, see 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 模式#
To set the static defect pixel correction mode, set the BslStaticDefectPixelCorrectionMode
参数设置为以下值:
Factory
(default): Static defect pixel correction is based on the defect pixels stored in the factory correction file.User
: Static defect pixel correction is based on the defect pixels stored in the user correction file.
Note that when setting this mode via the pylon API, only the user-defined pixels will be used. When setting the User incl. Factory correction mode via the pylon Viewer, user-defined pixels will be used in addition to the pixels stored in the factory file.Off
: The camera does not perform static defect pixel corrections.
上传用户 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 条目,您的相机不支持上传校正文件。 - 单击上传并导航到要上传的文件。
- 单击打开。
To apply the user defect pixel correction file after uploading, make sure that the BslStaticDefectPixelCorrectionMode
parameter is set to User
and execute the BslStaticDefectPixelCorrectionReload
command.
下载 Defect Pixel Correction 文件#
如果您想要将自己测量的缺陷像素添加到下载的文件中,下载 Defect Pixel Correction 文件(例如出厂校正文件)可能会很有用。您可以将缺陷像素条目的完整列表存储在新的用户校正文件中。
使用 pylon Viewer 下载 Defect Pixel Correction 文件:
- 在 pylon Viewer 的相机菜单中,单击文件访问权限。
- 在相机文件下拉框中,根据您要下载的文件,选择静态出厂 Defect Pixel Correction 或静态用户 Defect Pixel Correction。
如果没有适当的条目,则您的相机不支持下载文件。 - 单击下载,导航到要保存文件的目录,然后输入所需的文件名。
- 单击打开。
静态 Defect Pixel Correction 文件状态#
即: StaticDefectPixelCorrectionFileStatus
parameter can take the following values:
FileStatusUnknown
: The status of the defect pixel correction file is unknown. Acquire an image to change the file status.FileOk
: The defect pixel correction file is valid.FileNotFound
: The defect pixel correction file can't be found. It has never been uploaded or was deleted.FileEmpty
: The defect pixel correction file has no entries. The file header is valid but the file doesn't contain any defect pixels. The defect pixel correction process is aborted.InvalidHeader
: The defect pixel correction file header is invalid. The file must have a 4-byte file header.InvalidSize
: The defect pixel correction file size is invalid. The maximum number of defective pixels must not exceed 4096.InvalidSorting
: The sorting of entries in the defect pixel correction file is invalid. The defect pixel correction process is aborted.InvalidFileEntry
: At least one entry in the defect pixel correction file has an invalid size. The defect pixel correction process is aborted.InvalidClustering
: An invalid cluster has been found. Three or more adjacent pixels in a row are considered an invalid cluster. Any defect pixels between other defect pixels can't be corrected.
The defect pixel correction file can contain a maximum number of defect pixels. To get the number, get the value of the BslStaticDefectPixelCorrectionMaxDefects
parameter.
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
parameter to the desired correction mode:Factory
: Only defect pixels whose coordinates are stored in the factory file are corrected. The factory file is generated during camera production and can't be changed.User
: You can specify custom defect pixel coordinates.Off
: The camera does not perform static defect pixel corrections.
-
If you selected
User
:- 找出图像中的像素错误,并记下缺陷像素的 x 和 y 坐标。
- 设置
BslStaticDefectPixelCorrectionYCoordinate
parameter to the y coordinate of the first defect pixel. - 设置
BslStaticDefectPixelCorrectionXSelector
parameter toX0
. - 设置
BslStaticDefectPixelCorrectionXCoordinate
parameter to the x coordinate of the first defect pixel. - If there's another defect pixel with the same y coordinate, but a different x coordinate, set the
BslStaticDefectPixelCorrectionXSelector
parameter to the next entry, e.g.,X1
, and enter the next x coordinate. - 对所有其他像素错误重复步骤 b。
- Execute the
BslStaticDefectPixelCorrectionSave
command to save changes to flash memory.
信息
- You can use the
BslStaticDefectPixelCorrectionCount
parameter to check how many image pixels are currently being corrected. - You can set the
BslStaticDefectPixelCorrectionTestMode
parameter toOn
to set all corrected pixels to completely white. This helps to find pixels that are being corrected in your images.
删除缺陷像素坐标#
不能删除出厂文件中的像素坐标。
但是,您可以删除自定义缺陷像素坐标,即在“用户”校正模式下输入的坐标(请参阅上文)。为此:
-
如果要移除单个自定义缺陷像素坐标:
- 设置
BslStaticDefectPixelCorrectionYCoordinate
parameter to the y coordinate of the defect pixel. - 设置
BslStaticDefectPixelCorrectionXSelector
parameter to the entry that holds the x coordinate of the defect pixel, e.g.,X0
. - 设置
BslStaticDefectPixelCorrectionXCoordinate
parameter to 0xFFFF. - Execute the
BslStaticDefectPixelCorrectionSave
command to save changes to flash memory.
- 设置
-
如果要移除所有自定义缺陷像素坐标:
- Execute the
BslStaticDefectPixelCorrectionClearAll
command. This sets allBslStaticDefectPixelCorrectionXCoordinate
parameter values to 0xFFFF. - Execute the
BslStaticDefectPixelCorrectionSave
command to save changes to flash memory.
- Execute the
dart 和 pulse 相机#
Basler dart 和 pulse 相机可以执行两种类型的像素校正:
- The static pixel correction corrects pixels that have significantly lesser intensity values than their neighboring pixels, including completely black pixels.
- The dynamic pixel correction corrects pixels that have significantly higher intensity values than their neighboring pixels, including completely white pixels. An internal threshold value defines when a pixel is detected as a "hot pixel". "Dynamic" means that the defect pixel correction is calculated individually for each acquired image.
设置 Defect Pixel Correction 模式#
To set the defect pixel correction mode, set the BslDefectPixelCorrectionMode
参数设置为以下值:
On
(default): The camera performs static and dynamic pixel corrections.StaticOnly
: The camera performs the static pixel correction only.Off
: The camera does not perform pixel corrections.
示例代码#
ace 2 R/X, boost R, and dart M Cameras#
/* 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, "BslDefectPixelCorrectionMode", "Off");
CHECK(errRes);
您也可以使用 pylon Viewer 轻松设置参数。