Re: adding noise to an image
- From: Paul Davis <pjdavis engineering uiowa edu>
- Cc: gtkmm-list gnome org
- Subject: Re: adding noise to an image
- Date: Wed, 19 Oct 2005 05:30:34 -0500
Foster, Gareth wrote:
Don't you just set rgb to the same value for grey scale?
uint8 * p_buf = get_buf_blah_pseudo();
uint8 by_val = rand()%std::numeric_limits<uint8>::max_val;
std::fill(by_val, by_val + 3, by_val);
Gawd, how embarrising ...
uint8 * p_buf = get_buf_blah_pseudo();
uint8 by_val = rand()%std::numeric_limits<uint8>::max_val;
std::fill(p_buf, p_buf + 3, by_val);
Awoooo! Howling!
_______________________________________________
gtkmm-list mailing list
gtkmm-list gnome org
http://mail.gnome.org/mailman/listinfo/gtkmm-list
If I'm not mistaken, that would create an image of one pixel value.
Some assumptions:
img_size = image_width * image_height
get_image returns a 1D array ( generally the best way for storing image
data )
max_noise_magnitude is an unsigned char that is controlled by the slider.
MAX_VAL is the maximum value per pixel( 255 in this case using unsigned
char )
An implementation would be something more like:
unsigned char* img = get_image() ;
//Assuming a grey scale image ( ie one value per pixel )
for( int i = 0 ; i < img_size ; i++ )
{
//I read somewhere once that you should use the higher order bits
for better randomness.
//Hopefully this gives you a random value from -max / 2 to max / 2 (
or there abouts )
char alter_val = ( rand() >> 24 ) % max_noise_magnitude - (
max_noise_magnitude / 2 ) ;
if( img[ i ] + alter_val < 0 )
{
img[i] = 0 ;
}
else if( img[i] + alter_val > MAX_VAL )
{
img[i] = MAX_VAL ;
}
else
{
img[i] += alter_val ;
}
}
//Should have our noisy image here.
Then again if you really want to get into fun stuff, adding white noise
( ie noise of in a wideband frequency range ) you should look at doing
an FFT and adding noise in the frequency domain. But thats probably a
bit more drastic than the need for this application.
Adding noise is one of those "there is no right way" things. Its kind
of like, does this look noisy to you? There are different types of
noise and different ways to add it. But then again I'm not really heavy
into image processing so I'm not sure what to say is the recommended
way. Go read about image processing concepts. Those people know what
they're talking about a good deal of the time.
Cheers,
Paul
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]