Click to See Complete Forum and Search --> : Noisy images


Reunion
October 12th, 2004, 01:07 AM
Hello!

I've got quite strange question: where can I find algorithms and some code describing how to add Gaussian, Salt & Papper (and some other kinds) noise to images?

Thank you in advance.

dolomighty
October 12th, 2004, 05:23 AM
you need to have a gaussian random generator, wich is pretty easy to come up with, then you iterate thru all the pixels in your image, and add your PRN to the pixel: depending on the colorspace you're working with, you may need to weight the amount of randomness added.

to build a simple gaussian PRN generator, you can rely on the fact that when you multiply random variables together, the result tend to conform to standard (gaussian) distribution, so working with floats:


//-------------------------------------------------
float gausrand() {
float a = 1;
for( int i=0; i<5; i++ ) a *= rand() * 2.0 / RAND_MAX - 1.0;
return a * 0.5 + 0.5;
}


this function returns a random float in the 0 to 1 range, with approx standard distribution (ie, 0.5 will pop up very often)

Reunion
October 12th, 2004, 11:32 PM
Thank you.
And what about Salt & Papper noise?

dolomighty
October 13th, 2004, 05:29 AM
if you mean the kind of noise you get on the tv-set when it's a bit out of tune, you need speckels at random positions in the image.
again, depending on what you need, you can simply set the pixel to some intensity or vary the actul intensity... noise is noise.
i tend to use normalized coordinates, so x/y coords will be in range 0 to 1.
here some code:


for( i=0; i<10000; i++ ) {
float x = rand() * 1.0 / RAND_MAX;
float y = rand() * 1.0 / RAND_MAX;
float c = rand() * 1.0 / RAND_MAX;
set_pixel( x, y, c );
..or..
add pixel( x, y, c*2-1 );
}

Reunion
October 14th, 2004, 01:38 AM
Thank you very much!
I've got ferther questions:
1). Do you know other kinds of noise?
2). Do you know how to create a kind of noise, where a 'noise element' is a group of several pixels (a small random-shaped figure)?

Thank you in advance.

dolomighty
October 14th, 2004, 08:27 AM
for the "pattern noise" you can substitute the set_pixel function above with another function wich simply put several pixels every call, within a given radius.
the effect you get would be somewhat like an airbrush painting tool...
or maybe every set_pixel call with a put_image... and here you have to solve various problems, relating to image file handling, image memory handling, more complex/optimized clipping, bit block transfer algos, maybe even assembly...

by the way, there are not stated rules, techniques or so: you only need to experiment what comes into your mind, see the results and see if it fit your needs... in other words, hacking !

bye

Reunion
October 15th, 2004, 10:22 PM
I just thought there is a common algorithm...

Thank you.