void gamma_correctioncvMat& src cvMat& dst float K uchar LUT256; srccopyTodst; for int i = 0; i 256; i++ float f = i + 05f 255; float f = i 2550; f = powf K; LUTi = cvsaturate_castucharf2550f-
}
The function gamma_correction applies a gamma correction to the input image src and stores the result in the output image dst. The gamma correction is controlled by the parameter K, which is a floating-point value that determines the strength of the correction.
The function first creates a lookup table LUT that maps each input pixel value to its corresponding gamma-corrected value. This is done by iterating over all possible input pixel values (0-255), applying the gamma correction formula (f = i / 255.0; f = pow(f, K);) to each value, and storing the result in the LUT. The LUT is then used to apply the gamma correction to each pixel in the input image by iterating over all pixels in the image and replacing each pixel value with its corresponding value in the LUT.
The function supports both grayscale and color images by using different iterators to access pixels depending on the number of channels in the image. For grayscale images, a uchar iterator is used, while for color images, a Vec3b iterator is used to access the three color channels separately.
Note that the function uses cv::saturate_cast to ensure that the output pixel values are within the valid range of 0-255
原文地址: http://www.cveoy.top/t/topic/e9lD 著作权归作者所有。请勿转载和采集!