基于《Adaptive Local Tone Mapping Based on Retinex for High Dynamic Range Images 》
主要公式如下:
是全自适应输出的结果,我们这里就是需要得到他,
表示输入图像的luminance值(亮度值),
表示输入图像亮度值对的最大值,
表示输入亮度对数的平均值,如下式所示
c++主要代码:
void ALTM_Retinex(Mat img)
{
Mat grayimg;
cvtColor(img,grayimg,COLOR_RGB2GRAY);
grayimg.convertTo(grayimg, CV_64FC1, 1.0/255);
int len = grayimg.cols*grayimg.rows;
double Lwaver, Lwmax;
Mat gain = grayimg.clone();
getLwpara(grayimg,len, &Lwaver,&Lwmax);
for (int i = 0; i < grayimg.rows; ++i)
{
for (int j = 0; j < grayimg.cols; ++j)
{
double tmp = grayimg.at<double>(i, j);
gain.at<double>(i,j) = log(tmp / Lwaver + 1) / log(Lwmax / Lwaver + 1) / tmp;
if (grayimg.at<double>(i, j) == 0) gain.at<double>(i, j) = 0;
}
}
Mat channels[3];
split(img, channels);
channels[0].convertTo(channels[0], CV_64FC1, 1.0/255);
channels[1].convertTo(channels[1], CV_64FC1, 1.0/255);
channels[2].convertTo(channels[2], CV_64FC1, 1.0/255);
channels[0] = gain.mul(channels[0]);
channels[1] = gain.mul(channels[1]);
channels[2] = gain.mul(channels[2]);
Mat finalimg ;
merge(channels,3,finalimg);
imshow("final",finalimg);
waitKey(0);
}
处理效果如图:
参考博客:https://www.cnblogs.com/Imageshop/p/9460334.html