Replace pixel values using a defect map image. [more]

Categories: ImageCalibration

Keywords: image calibration, hot pixels, cool pixels, defects, bad pixels, bad columns, noise




Noise in images can be the result of several phenomena. From photonic noise due the low amount of incoming light, to thermal and electronic noise. Thermal and electronic noise are commonly handled by bias and darks, frames that modelate the signal from both sources. Due the nonlinear nature of extremelly bright or dark pixels, they are not corrected with this procedure, and remain after calibration. Hot pixels, dead pixels, defective columns, and others, do not contain valid information, and must be replaced with data from their neighbors.

DefectMap is a process that uses an image as a map indicating those defective pixels that need to be replaced. For each bad pixel, a neighbourhood is defined, and a user defined operation is performed to calculate the value that will stored at that location.

This process may handle normal grayscale or composed color images, as well as bayered (CFA matrix) one shot images (either grayscale or sepparated in color channels).


Defect map

This is the identifier of a main view that holds the information of the pixels that are going to be replaced by the DefectMap process. This image may be grayscale or color. As convention, black pixels are considered as defective pixels, and thus will be replaced. Other pixel values are incorporated in different ways, depending on the Operation parameter.


Select the algorithm that is used to calculate the new pixel values. Avalaible operations are:


This operation takes the average value of the neighbor pixels. Pixel values on the defect map are used as weighting values. White pixels (with value of 1.0) are fully incorporated in the averaging operation.


This operation is similar to the previous. Pixels are averaged following a gaussian distribution. Pixel values on the defect map are used as an extra weight, multiplied to the gaussian distribution value.


This operation replaces pixels with the minimum value of its neighbors. Black pixels are replaced, and white or gray pixels in the neighbourhood are included in the operation.


This operation replaces pixels with the maximum value of its neighbors. Black pixels are replaced, and white or gray pixels in the neighbourhood are included in the operation.


This operation replaces pixels with the median value of its neighbors. Black pixels are replaced, and white or gray pixels in the neighbourhood are included in the operation. If an even number of pixels is used as neighbors, the mean value of the central couple in the distribution is used.


This parameter defines the neighbourhood of pixels that are included in the calculation of the new value. A:


Pixels in a square neighbourhood are selected.


Only pixels whose eucludic distance is less or equal than a certain value are selected (inside a defined radius).


Only pixels in the same row are selected.


Only pixels in the same column are selected.

The size of the structure is automatically determined by NotchFilter to provide enough amount of samples to be statistically representative.


Use this parameter to force DefectMap to use only pixels that contains the same color information only. In grayscale bayered images, DefectMap will skip neighbors containing information of other channels. In RGB channel decomposed bayered images, this will help the algorithm to avoid zero values to contaminate the statistics or calculations.


Defect Map

Building the correct defect map to be used by this process is often possible with the aid of master calibration frames. Darks are ussually the most important source to propperlly segment bad pixels.

Several methods may be used to create a propper Defect Map:

Figure 1

This is crop section of a image taken with a Canon 300D camera. As seeing in the RAW image, it contains a lot of noise, at this level of stretching. Subtraction of Bias and Dark frames cleans significantly the image, but some hot pixels were overcorrected, creating dark holes in the image. Build of a defect map was done using the master dark frame as starting point, and thresholding with the Binarize process at a level were all of the hot pixels were selected. It is shown the result of applying DefectMap with default Operation and Structure parameters, and the Is CFA option enabled. At last, is the defect map used. Image courtesy of Carlos Milovic (PTeam).


Usually, Mean and Median operators yield similar results. Gaussian weighting adds more weights to pixels closer to the selected ones, so it may be usefull if the neighbourhood of the pixels will contain several black pixels (not included in the calculation), and thus, the automatic growth of the structure has to incorporate pixels far from the current location.

Minimum and maximum operations are included for completitude. For normal applications, the previous operation methods are suggested.


The structure selection should correspond to the information in the defect map. If several pixels are selected in the same row, a vertical structure is suggested. Circular structures are more restrictive than square ones, and thus the automatic growth may use larger structures to find sufficient pixel samples.

Related Tools

NotchFilter, ImageCalibration