# Gaussian white noise (randon numbers)

This topic is 2084 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

What's the correct way to go about simulating Gaussian white noise in an image? For example, the type that might be added by thermal noise in an image sensor or the fuzz of an analog TV signal. I'm using C++11 which already has RNGs with normal distributions available, so I am not asking how to implement a Gaussian RNG, simply how to use it correctly.

##### Share on other sites

Create a random number engine for the source of randomness and a distribution to shape the random numbers, then call the distribution object with the engine object to obtain a random number with the given distribution.

std::default_random_engine engine;
std::normal_distribution<double> dist(mean, deviation);

double value = dist(engine);


##### Share on other sites

http://stackoverflow.com/questions/14009637/c11-random-numbers

Suggests:

#include <random>
#include <iostream>

static std::mt19937_64 rng;

int main() {

for (int i = 0; i < 10; ++ i)
std::cout << rng() << std::endl;
}
Edited by TheComet

##### Share on other sites

If you need integral values instead of floats, you could use a binomial distribution instead.  Similar results for your purposes, fewer transcendent functions required.

##### Share on other sites

I did the T.V. noise effect in opengl (for a screensaver) simply by using a texture four time smaller than the viewport, then i just filled the texture each frame with normal random values and let opengl filter the texture for me, giving a very reallistic effect imo.

Edited by Vortez

##### Share on other sites

So, should I use a Gaussian distribution with a mean of 0 and then use the stddev to control the amount of noise? At that point I simply add the noise to the image and clamp to [0, 1]? But if I clamp, wouldn't that mean that 0 and 1 will become more probable?

##### Share on other sites

So, should I use a Gaussian distribution with a mean of 0 and then use the stddev to control the amount of noise? At that point I simply add the noise to the image and clamp to [0, 1]? But if I clamp, wouldn't that mean that 0 and 1 will become more probable?

Don't clamp (otherwise you'll most likely get 1 all the time). Whatever noise function you use, be sure to map it to [0, 1] before applying it.

##### Share on other sites

Yes, that's what happens when you clamp a Gaussian distribution. But then you're talking about more theoretical rather than practical cases, and in theory the noise/static in a TV-image is not Gaussian because the noise is limited to the dynamic range of the display but Gaussian random values can attain values between positive and negative infinity.

• 13
• 18
• 29
• 11
• 27