Chromatic Aberration Correction#
Detailed Description#
Function Documentation#
correctChromaticAberration()#
void cv::correctChromaticAberration(
InputArray input_image,
InputArray coefficients,
OutputArray output_image,
const Size & image_size,
int calib_degree,
int bayer_pattern = -1 )
#include <opencv2/photo.hpp>
Python:
cv.correctChromaticAberration(input_image, coefficients, image_size, calib_degree[, output_image[, bayer_pattern]]) -> output_image
Corrects lateral chromatic aberration in an image using polynomial distortion model.
This function loads polynomial calibration data from the specified file and applies a channel‐specific warp to remove chromatic aberration. If input_image has one channel, it is assumed to be a raw Bayer image and is first demosaiced using bayer_pattern. If it has three channels, it is treated as a BGR image and bayer_pattern is ignored.
Firstly, calibration needs to be done using apps/chromatic-aberration-calibration/ca_calibration.py on a photo of a pattern of black discs on white background, included in opencv_extra/testdata/cv/cameracalibration/chromatic_aberration/chromatic_aberration_pattern_a3.png
Calibration and correction are based on the algorithm described in [258]. The chromatic aberration is modeled as a polynomial of some degree in red and blue channels compared to green. In calibration, a photo of many black discs on white background is used, and the displacements between the centres of discs in red and blue channels compared to green are minimized. The coefficients are then saved in a yaml file which can be used with this function to correct lateral chromatic aberration.
See also
Parameters
input_image— Input BGR image to correctcoefficients— Coefficient modeloutput_image— Corrected BGR imageimage_size— Size of images for the calibration coefficient modelcalib_degree— Degree of the calibration coefficient modelbayer_pattern— Bayer pattern code (e.g. cv::COLOR_BayerBG2BGR) used for demosaicing wheninput_imagehas one channel; ignored otherwise.
loadChromaticAberrationParams()#
void cv::loadChromaticAberrationParams(
const FileNode & node,
OutputArray coeffMat,
Size & calib_size,
int & degree )
#include <opencv2/photo.hpp>
Python:
cv.loadChromaticAberrationParams(node[, coeffMat]) -> coeffMat, calib_size, degree
Load chromatic-aberration calibration parameters from opened FileStorage.
R e*ads the red and blue polynomial coefficients from the specified file and packs them into a 4×N CV_32F matrix: row 0 = blue dx coefficients row 1 = blue dy coefficients row 2 = red dx coefficients row 3 = red dy coefficients
See also
Parameters
node— Node of opened cv::FileStorage object.coeffMat— Output 4xN coefficient matrix (CV_32F).degree— Polynomial degree inferred from N.calib_size— Calibration image size read from file.