0

I was wondering if you could give me some advice on how to add impulsive and Gamma noise to an image separately? It's so easy with imnoise function of matlab, but i'm not allowed to use imnoise, Our TA said you can just use rand function.

I came across this code but it seems it doesn't work as it should(for impulse noise):

    noisyimage=originalimage+255*rand(size(originalimage)); 
Rman Edv
  • 163
  • 1
  • 17
  • That will add white noise to your image, but it assumes your image is uint8 where yours might be double. if it's double just drop the 255. – Dan Apr 25 '13 at 14:04
  • @Dan thanks buddy, it worked..but what about Gamma noise? i couldn't find its code on the web :( – Rman Edv Apr 25 '13 at 14:12

1 Answers1

1

There's a few issues with that line of code:

  • 255*rand() generates double-valued numbers, whereas your image will probably be of type uint8 or so (check with class(originalimage)). To fix, use randi for instance:

    noisyimage = randi(255, size(originalimage), class(originalimage));
    

    (use intmax(class(originalimage)) to be completely generic)

  • you add noise of maximum magnitude 255 to all pixels. This might overflow many of your pixels (that is, get assigned values higher than 255). To avoid, use something like

    noisyimage = min(255, originalimage + randi(...) );
    
  • The noise direction is only positive. True noise also sometimes brings down the values of the pixels. So, use something like

    noisyimage = max(0, min(255, originalimage + randi(...)-127 );
    
  • the maximum amplitude of 255 is actually way too big; you'll likely destroy your whole image and only get noise. Try a few different amplitudes, A, like so:

    noisyimage = max(0, min(255, originalimage + randi(A, ...)-round(A/2) );
    
  • The uniform distribution which randi uses is not a really good source of noise; you'd want some other distribution. Use the normal distribution:

    uint8(A*randn(...)-round(A/2))
    

    or gamma:

    uint8(A*randg(...)-round(A/2))
    

    etc.

Now, that should get you started :)

Rody Oldenhuis
  • 37,726
  • 7
  • 50
  • 96
  • Dear friend, Thanks for your help, But i still cannot figure it out how to add Gamma noise to a RGB image – Rman Edv Apr 25 '13 at 14:38
  • @rody For your first point, I am wondering if '3' is necessary? Because for a RGB image `size` already returns something like 1500 * 2000 * 3. Isn't it? – momo Sep 26 '18 at 17:16