Defect Pixel Correction#
In acquired images, some pixels may appear significantly brighter or darker than the rest, even if uniform light is used. This problem is caused by differences in sensitivity of the individual pixels which in turn are due to production tolerances.
Using the Feature#
ace 2 and boost Cameras#
Basler ace 2 and boost 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.
"Static" means that always the same specified defect pixel coordinates are used for the correction process. During image acquisition, the intensity values of exactly these pixels are replaced based on the intensity values of their neighboring pixels.
The following defect pixel correction files can be stored on the camera:
- Factory file: Contains the coordinates of defect pixels that were detected during camera production. With this file, the camera corrects pixels that have a significantly lesser intensity value than the neighboring pixels, including completely black pixels.
- User file: Contains user-defined coordinates. You can upload this file to the camera. This allows you to define new defect pixels that might have occurred over time, regardless of whether these pixels are too dark or too bright.
Correcting Defect Pixels Using the pylon Viewer#
→ See Static Defect Pixel Correction (pylon Viewer).
Correcting Defect Pixels Using the pylon API#
Info
Basler recommends performing defect pixel correction using the pylon Viewer.
Only use the pylon API if you want to implement defect pixel correction in your own application.
Setting the Static Defect Pixel Correction Mode#
To set the static defect pixel correction mode, set the BslStaticDefectPixelCorrectionMode
parameter to one of the following values:
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.Off
: The camera does not perform static defect pixel corrections.
Uploading a User Defect Pixel Correction File#
Before uploading a user defect pixel correction file, make sure that the file conforms to the following file format:
The file must start with a 4-byte header containing four bytes with value 0. Following the header, the file must contain defect pixel entries (up to 4096 defect pixels can be specified). Each entry consists of 32 bits with the following order: 14 bits y-coordinate, 14 bits x-coordinate, 4 bits type
Example: Defect pixel entry with the coordinate x = 1 and y = 2
Bit |31 18| |17 4| |3 0|
Value |00000000000010| |00000000000001| |0000|
| y = 2 | | X = 1 | |type|
To upload a user defect pixel correction file using the pylon Viewer:
- In the Camera menu of the pylon Viewer, click File Access.
- In the Camera File drop-down box, select User Defect Pixel Correction.
If there's no User Defect Pixel Correction entry, uploading correction files is not supported by your camera. - Click Upload and navigate to the file that you want to upload.
- Click Open.
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.
Downloading a Defect Pixel Correction File#
Downloading a defect pixel correction file, e.g., the factory correction file, might be useful if you want to add your own measured defect pixels to the downloaded file. You can store the complete list of defect pixel entries in a new user correction file.
To download a defect pixel correction file using the pylon Viewer:
- In the Camera menu of the pylon Viewer, click File Access.
- In the Camera File drop-down box, select Static Factory Defect Pixel Correction or Static User Defect Pixel Correction depending on which file you want to download.
If there's no appropriate entry, downloading files is not supported by your camera. - Click Download, navigate to the directory where you want to save the file, and enter the desired file name.
- Click Open.
Static Defect Pixel Correction File Status#
The 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.
dart and pulse Cameras#
Basler dart and pulse cameras can perform two types of pixel corrections:
- The static pixel correction corrects pixels that have a significantly lesser intensity value than its neighboring pixels, including completely black pixels.
- The dynamic pixel correction corrects pixels that have a significantly greater intensity value than its 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.
Setting the Defect Pixel Correction Mode#
To set the defect pixel correction mode, set the BslDefectPixelCorrectionMode
parameter to one of the following values:
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.
Sample Code#
ace 2 and boost Cameras#
// Set static user defect pixel correction
camera.BslStaticDefectPixelCorrectionMode.SetValue(BslStaticDefectPixelCorrectionMode_User);
// Reload static defect pixel correction file
camera.BslStaticDefectPixelCorrectionReload.Execute();
INodeMap& nodemap = camera.GetNodeMap();
// Set static user defect pixel correction
CEnumParameter(nodemap, "BslStaticDefectPixelCorrectionMode").SetValue("User");
// Reload static defect pixel correction file
CCommandParameter(nodemap, "BslStaticDefectPixelCorrectionReload").Execute();
// Set static user defect pixel correction
camera.Parameters[PLCamera.BslStaticDefectPixelCorrectionMode].SetValue(PLCamera.BslStaticDefectPixelCorrectionMode.User);
// Reload static defect pixel correction file
camera.Parameters[PLCamera.BslStaticDefectPixelCorrectionReload].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 static user defect pixel correction */
errRes = PylonDeviceFeatureFromString(hdev, "BslStaticDefectPixelCorrectionMode", "User");
CHECK(errRes);
/* Reload static defect pixel correction file */
errRes = PylonDeviceExecuteCommandFeature(hdev, "BslStaticDefectPixelCorrectionReload");
CHECK(errRes);
dart and pulse Cameras#
// Disable defect pixel correction
camera.BslDefectPixelCorrectionMode.SetValue(BslDefectPixelCorrectionMode_Off);
INodeMap& nodemap = camera.GetNodeMap();
// Disable defect pixel correction
CEnumParameter(nodemap, "BslDefectPixelCorrectionMode").SetValue("Off");
// Disable defect pixel correction
camera.Parameters[PLCamera.BslDefectPixelCorrectionMode].SetValue(PLCamera.BslDefectPixelCorrectionMode.Off);
/* 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);
You can also use the pylon Viewer to easily set the parameters.