Flat-Field Correction#
機能を使用する#
仕組み#
Non-uniformities in images are a common occurrence in digital imaging. These are caused by variations in the brightness output of sensor pixels as well as by the influence of light source and illuminations optics. Flat-field correction minimizes these non-uniformities by correcting the original pixel values, thus improving image quality and subsequent analysis.
Before flat-field correction can be applied, the camera needs to be calibrated. This involves calculating appropriate correction data. With this, the original pixels can be corrected during image acquisition resulting in an improved image.
Types of Flat-Field Correction#
The implementation of the Flat-Field Correction feature varies depending on the type of flat-field correction used. Basler boost V cameras support block-based and column-based flat-field correction.
Block-based flat-field correction corrects image artifacts caused by photo response non-uniformities (PRNU) and low frequency variations deriving from the illumination and illumination optics. Block-based FFC "divides" the sensor into square blocks consisting of a certain number of pixels. During calibration, correction data is calculated for each square block, which is then interpolated and applied to each pixel of the sensor.
Column-based flat-field correction corrects image artifacts caused by dark signal non-uniformities (DSNU) and photo response non-uniformities (PRNU). For each column of the sensor, a correction value for both DSNU and PRNU must be calculated during calibration. During image acquisition, these column-wise correction values are applied to the original pixel values.
The following drawing shows the different principles of block-based and column-based flat-field correction.
Creating Correction Values (CV)#
Block-based flat-field correction: A sequence of bright field (flat field) images is taken to detect photo response non-uniformities (PRNU) and low frequency artifacts caused by, e.g., lighting or optics. The correction values (CV) are calculated by the camera and saved to the camera's flash memory.
Column-based flat-field correction: A sequence of dark field images is taken (A) to detect dark signal non-uniformities (DSNU) (dark current noise) and a sequence of bright field (flat field) images is taken (B) to detect photo response non-uniformities (PRNU). The correction values (CV) must then be calculated by the user and saved to the camera's flash memory.
Applying Flat-Field Correction#
The image artifacts are removed, provided that the flat-field correction feature is enabled. The original pixel values (OV) are corrected resulting in an improved image (Resulting Values, RV).
Block-Based Flat-Field Correction#
Creating a Flat-Field Correction Set#
This step involves calibrating the camera and storing the calculated correction values in a file referred to as a flat-field correction set. You can create up to 16 correction sets.
You need the following item before you start creating a flat-field correction set:
- A target with a uniform background, e.g., a white sheet of paper
情報
For best results, adjust the optics, frame rate, exposure time, gain, and camera temperature as you would for normal operation. Basler recommends acquiring the bright field images in your actual application environment.
To create a flat-field correction set:
- Set the
Width
andHeight
parameters of the image ROI to their maximum values. - Disable the Decimation and Dual ROI features, if available.
- Disable Binning.
- Set Reverse X and Reverse Y as you would for later operation.
- Illuminate the sensor homogeneously to 70 % saturation, e.g., by placing a white sheet of paper in the camera's entire field of view.
- Set the
BslFlatFieldCorrectionSelector
parameter toBlockBased
. - Set the
BslFlatFieldCorrectionMode
parameter toOn
. - Set the
BslFlatFieldCorrectionSetIndex
parameter to the desired index number of the set to be created, e.g., 2. - Click the Continuous Shot button in the toolbar of the pylon Viewer to start image acquisition.
- Execute the
BslFlatFieldCorrectionSetCreate
command to create a new flat-field correction set.
A sequence of bright images is acquired and evaluated. The resulting correction data are generated and collected in the flat-field correction set selected. -
Save the settings to the camera's flash memory by executing the
BslFlatFieldCorrectionSetSave
command.
If the flat-field correction set with, e.g., index number 2, already contains correction data, these are overwritten and replaced by the new correction values.The created flat-field correction set is enabled automatically.
Enabling a Flat-Field Correction Set#
To enable a flat-field correction set:
- Set the
BslFlatFieldCorrectionMode
parameter toOn
. - Set the
BslFlatFieldCorrectionSetIndex
parameter to the index number of the set to be used, e.g., index number 2. - Execute the
BslFlatFieldCorrectionSetLoad
command.
情報
Changing a flat-field correction set is possible during image acquisition. However, slight image artifacts may occur during that process.
Column-Based Flat-Field Correction#
情報
This feature is complemented by the Flat-Field Correction (pylon Viewer) feature.
Calculating the Correction Values Using the pylon Viewer#
→ See Flat-Field Correction (pylon Viewer).
Calculating the Correction Values Using the pylon API#
The following mathematical parameters are involved:
- DMean: mean gray value of all pixels in the dark field image
- GMean: mean gray value of all pixels in the bright field image
- DSNU_Coeff(x): dark signal non-uniformity (DSNU) coefficient
- PRNU_Coeff(x): photo response non-uniformity (PRNU) coefficient
- UserGD_Offset: user-defined global dark offset
where x is the column index.
情報
For best results, acquire the dark and bright field images in your actual application environment. Be aware that only static effects can be corrected. If you change, e.g., the lens or lighting, you must repeat this procedure.
To calculate the correction values:
- Protect the sensor from light, e.g., by placing a plastic cap on the lens, and acquire a sequence of dark images.
- Sum up the gray values of all pixels in all acquired images and divide the sum by the total number of pixels. The result is the mean gray value of all pixels in the dark field image (DMean).
- Calculate the mean gray value for each column x (D(x)).
- Illuminate the sensor homogeneously to 70 % saturation, e.g., by placing a white sheet of paper in the camera's entire field of view, and acquire a sequence of bright images.
- Sum up the gray values of all pixels in all acquired images and divide the sum by the total number of pixels. The result is the mean gray value of all pixels in the bright field image (GMean).
- Calculate the mean gray value for each column x (G(x)).
- If necessary, determine a global dark offset value according to your needs (UserGD_Offset).
-
For each column x, calculate the coefficients DSNU_Coeff(x) and PRNU_Coeff(x) as follows:
-
Use the calculated values for setting the corresponding camera parameters via the pylon API.
- Column index (x):
BslFlatFieldCorrectionCoeffX
- DMean:
BslFlatFieldCorrectionDMean
- DSNU_Coeff(x):
BslFlatFieldCorrectionCoeffDSNU
- PRNU_Coeff(x):
BslFlatFieldCorrectionCoeffPRNU
- UserGD_Offset:
BslFlatFieldCorrectionUserGD
- Column index (x):
-
After having set all correction values for all columns, you can test flat-field correction by acquiring a series of images.
- If you're satisfied with the image quality, save the settings to the camera's flash memory by executing the
BslFlatFieldCorrectionSaveToFlash
command.
Choosing the Flat-Field Correction Type#
The BslFlatFieldCorrectionSelector
allows you choose the flat-field correction type to be used. You can set the parameter to the following values:
BlockBased
: Block-based flat-field correction is performed.ColumnBased
: Column-based flat-field correction is performed.
Enabling or Disabling Flat-Field Correction#
To enable or disable flat-field correction, set the BslFlatFieldCorrectionMode
parameter to one of the following values:
On
: The camera performs flat-field correction depending on the flat-field correction type chosen.DSNUOnly
: The camera performs DSNU correction only.
Note: This parameter value is only available when choosing column-based flat-field correction.Off
(default): The camera does not perform the flat-field correction type chosen.
外部リンク#
サンプルコード#
Block-Based Flat-Field Correction#
// Set the type of flat-field correction to Block-Based
camera.BslFlatFieldCorrectionSelector.SetValue(BslFlatFieldCorrectionSelector_BlockBased);
// Set the flat-field correction mode to On
camera.BslFlatFieldCorrectionMode.SetValue(BslFlatFieldCorrectionMode_On);
// Set the desired index number of the set to be created
camera.BslFlatFieldCorrectionSetIndex.SetValue(BslFlatFieldCorrectionSetIndex_1);
// Create new flat-field correction data for the flat-field correction set selected
camera.BslFlatFieldCorrectionSetCreate.Execute();
// Save the correction data to the camera's flash memory
camera.BslFlatFieldCorrectionSetSave.Execute();
INodeMap& nodemap = camera.GetNodeMap();
// Set the type of flat-field correction to Block-Based
CEnumParameter(nodemap, "BslFlatFieldCorrectionSelector").SetValue("BlockBased");
// Set the flat-field correction mode to On
CEnumParameter(nodemap, "BslFlatFieldCorrectionMode").SetValue("On");
// Set the desired index number of the set to be created
CEnumParameter(nodemap, "BslFlatFieldCorrectionSetIndex").SetValue("");
// Create new flat-field correction data for the flat-field correction set selected
CCommandParameter(nodemap, "BslFlatFieldCorrectionSetCreate").Execute();
// Save the correction data to the camera's flash memory
CCommandParameter(nodemap, "BslFlatFieldCorrectionSetSave").Execute();
// Set the type of flat-field correction to Block-Based
camera.Parameters[PLCamera.BslFlatFieldCorrectionSelector].SetValue(PLCamera.BslFlatFieldCorrectionSelector.BlockBased);
// Set the flat-field correction mode to On
camera.Parameters[PLCamera.BslFlatFieldCorrectionMode].SetValue(PLCamera.BslFlatFieldCorrectionMode.On);
// Set the desired index number of the set to be created
camera.Parameters[PLCamera.BslFlatFieldCorrectionSetIndex].SetValue(PLCamera.BslFlatFieldCorrectionSetIndex.);
// Create new flat-field correction data for the flat-field correction set selected
camera.Parameters[PLCamera.BslFlatFieldCorrectionSetCreate].Execute();
// Save the correction data to the camera's flash memory
camera.Parameters[PLCamera.BslFlatFieldCorrectionSetSave].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 type of flat-field correction to Block-Based */
errRes = PylonDeviceFeatureFromString(hdev, "BslFlatFieldCorrectionSelector", "BlockBased");
CHECK(errRes);
/* Set the flat-field correction mode to On */
errRes = PylonDeviceFeatureFromString(hdev, "BslFlatFieldCorrectionMode", "On");
CHECK(errRes);
/* Set the desired index number of the set to be created */
errRes = PylonDeviceFeatureFromString(hdev, "BslFlatFieldCorrectionSetIndex", "");
CHECK(errRes);
/* Create new flat-field correction data for the flat-field correction set selected */
errRes = PylonDeviceExecuteCommandFeature(hdev, "BslFlatFieldCorrectionSetCreate");
CHECK(errRes);
/* Save the correction data to the camera's flash memory */
errRes = PylonDeviceExecuteCommandFeature(hdev, "BslFlatFieldCorrectionSetSave");
CHECK(errRes);
# Set the type of flat-field correction to Block-Based
camera.BslFlatFieldCorrectionSelector.Value = "BlockBased"
# Set the flat-field correction mode to On
camera.BslFlatFieldCorrectionMode.Value = "On"
# Set the desired index number of the set to be created
camera.BslFlatFieldCorrectionSetIndex.Value = ""
# Create new flat-field correction data for the flat-field correction set selected
camera.BslFlatFieldCorrectionSetCreate.Execute()
# Save the correction data to the camera's flash memory
camera.BslFlatFieldCorrectionSetSave.Execute()
Column-Based Flat-Field Correction#
// Example: Set all correction values for all columns
// Dark signal non-uniformity (DSNU) coefficient
// CalculatedDSNU[0..width-1]
// Photo response non-uniformity (PRNU) coefficient
// CalculatedPRNU[0..width-1]
for (x=0; ++x; x<width)
{
camera.BslFlatFieldCorrectionCoeffX.SetValue(x);
camera.BslFlatFieldCorrectionCoeffDSNU.SetValue(CalculatedDSNU[x]);
camera.BslFlatFieldCorrectionCoeffPRNU.SetValue(CalculatedPRNU[x]);
}
// Set the global dark offset value
camera.BslFlatFieldCorrectionUserGD.SetValue(40)
// Save the settings to the camera's flash memory
camera.BslFlatFieldCorrectionSaveToFlash.Execute();
// Set the type of flat-field correction to Column-Based
camera.BslFlatFieldCorrectionSelector.SetValue(BslFlatFieldCorrectionSelector_ColumnBased);
// Set the flat-field correction mode
camera.BslFlatFieldCorrectionMode.SetValue(BslFlatFieldCorrectionMode_On);
このサンプルコードは、C++言語でのみ使用できます。
pylon Viewerを使用して、パラメーターを簡単に設定することもできます。