How to add impulsive and gamma noise to an image without using imnoise function in matlab? -
i wondering if give me advice on how add impulsive , gamma noise image separately? it's easy imnoise function of matlab, i'm not allowed use imnoise, our ta said can use rand function.
i came across code seems doesn't work should(for impulse noise):
noisyimage=originalimage+255*rand(size(originalimage));
there's few issues line of code:
if image rgb (e.g., loaded colour jpeg or something), you'll have add 3 layers of noise; e.g., use
rand([size(originalimage) 3])
255*rand()
generates double-valued numbers, whereas image of typeuint8
or (checkclass(originalimage)
). fix, userandi
instance:noisyimage = randi(255, [size(originalimage) 3], class(originalimage));
you add noise of maximum magnitude 255 all pixels. might overflow many of pixels (that is, assigned values higher 255). avoid, use
noisyimage = min(255, originalimage + randi(...) );
the noise direction positive. true noise brings down values of pixels. so, use
noisyimage = max(0, min(255, originalimage + randi(...)-127 );
the maximum amplitude of 255 way big; you'll destroy whole image , noise. try few different amplitudes,
a
, so:noisyimage = max(0, min(255, originalimage + randi(a, ...)-round(a/2) );
the uniform distribution
randi
uses not source of noise; you'd want other distribution. use normal distribution:uint8(a*randn(...)-round(a/2))
or gamma:
uint8(a*randg(...)-round(a/2))
etc.
now, should started :)