OpenCV中的本地规范化 [英] Local normalization in OpenCV
问题描述
我想在OpenCV中实现一个局部归一化算法,以减少图像中的照明差异。我找到了一个 MATLAB函数,我已在OpenCV中实现它。但是,我得到的结果不同于MATLAB函数给出的结果。
I'm trying to implement in OpenCV a local normalization algorithm to reduce the difference of illumination in an image. I have found a MATLAB function, and I have implemented it in OpenCV. However, the result that I get is different from the one given by the MATLAB function.
这是我的代码:
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;
}
函数 NormInv
是Euan Dean在 this post 。
The function NormInv
is the C++ implementation given by Euan Dean in this post.
下面显示了我获得的结果和理论结果,对于 sigma1
和 sigma2
(分别为2.0和20.0)
The following shows the result that I am getting and the theoretical result, for the same values of sigma1
and sigma2
(2.0 and 20.0, respectively)
我尝试对 sigma1
和 sigma2
使用不同的值,但它们都不起作用。我也尝试在高斯函数 blur1 = 0
和 blur2 = 0
,但它也不工作。
I have tried using different values for sigma1
and sigma2
, but none of them seem to work. I have also tried doing blur1=0
and blur2=0
in the Gaussian function but it doesn't work either.
任何帮助将不胜感激。提前感谢。
Any help would be appreciated. Thanks in advance.
推荐答案
您需要在0到255之间将图像标准化,然后再将其转换为CV_8UC1
you need to normalize the image between 0 and 255 before converting it to CV_8UC1
这篇关于OpenCV中的本地规范化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!