我试图在OpenCV中实现局部归一化算法,以减少图像中的照明差异.我找到了一个MATLAB函数,我在OpenCV中实现了它.但是,我得到的结果与MATLAB函数给出的结果不同.
这是我的代码:
Mat localNorm(Mat image, float sigma1, float sigma2)
{
Mat floatGray, blurred1, blurred2, temp1, temp2, res;
image.convertTo(floatGray, CV_32FC1);
floatGray = floatGray/255.0;
int blur1 = 2*ceil(-NormInv(0.05, 0, sigma1))+1;
cv::GaussianBlur(floatGray, blurred1, cv::Size(blur1,blur1), sigma1);
temp1 = floatGray-blurred1;
cv::pow(temp1, 2.0, temp2);
int blur2 = 2*ceil(-NormInv(0.05, 0, sigma2))+1;
cv::GaussianBlur(temp2, blurred2, cv::Size(blur2,blur2), sigma2);
cv::pow(blurred2, 0.5, temp2);
floatGray = temp1/temp2;
floatGray = 255.0*floatGray;
floatGray.convertTo(res, CV_8UC1);
return res;
}
Run Code Online (Sandbox Code Playgroud)
该函数NormInv是Euan Dean在这篇文章中给出的C++实现.
以下显示了我得到的结果和理论结果,对于相同的值sigma1和sigma2(分别为2.0和20.0)

我一直在使用不同的值试过sigma1和sigma2,但他们都不工作.我也尝试过在高斯函数中做 …