I am trying to implement a local normalization algorithm in OpenCV to reduce the difference in illumination in the image. I found the MATLAB function and I implemented it in OpenCV. However, the result I get is different from the result set by the MATLAB function.
This is my code:
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;
}
A function NormInvis a C ++ implementation given by Euan Dean in this post .
Below is the result that I get and the theoretical result for the same values sigma1and sigma2(2.0 and 20.0 respectively)

I tried using different values for sigma1and sigma2, but none of them work. I also tried to do blur1=0, and blur2=0in the Gauss function, but it does not work.
. .