Gaussian white noise (randon numbers)

Started by
7 comments, last by Brother Bob 10 years, 5 months ago

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.

Advertisement

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);

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

Suggests:


#include <random>
#include <iostream>

static std::mt19937_64 rng;

int main() {
    rng.seed(/*put your seed here*/);

    for (int i = 0; i < 10; ++ i)
        std::cout << rng() << std::endl;
}
"I would try to find halo source code by bungie best fps engine ever created, u see why call of duty loses speed due to its detail." -- GettingNifty

I'll just put this link here for the sake of completion:
http://channel9.msdn.com/Events/GoingNative/2013/rand-Considered-Harmful

visualnovelty.com - Novelty - Visual novel maker

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

Stephen M. Webb
Professional Free Software Developer

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.

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?

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.

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.

This topic is closed to new replies.

Advertisement