Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

OpenCV - Gaussian Noise

Hello,

here's my problem: I'm trying to create a simple program which adds Gaussian noise to an input image. The only constraints are that the input image is of type CV_64F (i.e. double) and the values are and must be kept normalized between 0 and 1.

The code I wrote is the following:

Mat my_noise;
my_ noise = Mat (input.size(), input.type());

randn(noise, 0, 5); //mean and variance

input += noise;

The above code doesn't work, the resulting image doesn't get displayed properly. I think that happens because it gets out of the 0,1 range. I modified the code like this:

Mat my_noise;
my_ noise = Mat (input.size(), input.type());

randn(noise, 0, 5); //mean and variance

input += noise;

normalize(input, input, 0.0, 1.0, CV_MINMAX, CV_64F);

but it still doesn't work. Again, the resulting image doesn't get displayed properly. Where is the problem? Remember: the input image is of type CV_64F and the values are normalized between 0 and 1 before adding noise and have to remain like also after the noise addition.

Thank you in advance.