OpenCV: Normalizing pixel values of an image

I am trying to normalize the pixel values of an image to have a mean value of 0.0 and a norm of 1.0 to give the image a consistent intensity. There is one OpenCV function, ie cvNormalize(src,dst,0,1,cv_MINMAX) , but can this function be used for my purpose? Any help is appreciated. Thank you.


No, the documentation for normalize says :

When normType=NORM_MINMAX (for dense arrays only), the functions normalize scale and shift the input array elements so that:

equations http://docs.opencv.org/_images/math/31bceb122fccfc14279355379f91c7b269290386.png

Hence, if you use normalize(src, dst, 0, 1, NORM_MINMAX, CV_32F); , your data will be normalized so that the minimum is 0 and the maximum is 1.

It is not clear what you mean by giving the pixel values of the image mean 0.0 and a norm of 1.0. As you wrote it, I understand that you want to normalize the pixel values so that the norm of the vector obtained by stacking image columns is 1.0. If that is what you want, you can use meanStdDev (documentation) and do the following (assuming your image is grayscale):

cv::Scalar avg,sdv;
cv::meanStdDev(image, avg, sdv);
sdv.val[0] = sqrt(image.cols*image.rows*sdv.val[0]*sdv.val[0]);
cv::Mat image_32f;
image.convertTo(image_32f,CV_32F,1/sdv.val[0],-avg.val[0]/sdv.val[0]);

If you just want to normalize so that the variance of the pixel values is one, ignore the third line.

And yes, the CV_32F means that the resulting image will use 32 bit floating point datatype (ie float ).

链接地址: http://www.djcxy.com/p/15876.html

上一篇: Opencv C ++错误,无法获取某些像素的像素强度值

下一篇: OpenCV:标准化图像的像素值