JakkaJan
JakkaJan

Reputation: 51

Octave/Matlab - Gaussian noise

I'm using imnoise in Octave to add gaussian noise to binary images but i think my question is general enough to apply to Matlab as well.

I'm using imnoise (A, 'gaussian' [, mean [, var]]) like this:

imnoise (A, 'gaussian', 0, var)

I vary var from 0.0 to 1.0. I think varying var from 0.0 to 1.0 is the same as varying noise percentage from 0% to 100%.

Am I correct? Because, in differant image sizes it gives inconstant level of noise. Smaller images would appear less noise compared to larger images with the same var.

Thanks

Upvotes: 1

Views: 4268

Answers (1)

carandraug
carandraug

Reputation: 13091

If you take a look at the source of imnoise (Octave is free software and you're encouraged to look at the source), you'll see that gaussian noise is implemented with:

## Variance of Gaussian data with mean 0 is E[X^2]
A = A + (a + randn (size (A)) * sqrt (b));

where A is your image (after conversion to the double and range [0 1], a is the mean, and b is the variance. Basically it takes random number from a normal distribution with the specified variance, and adds to the image.

I'm unsure of what you mean by noise percentage but it shouldn't be changing based on the image size. If by percentage you mean how much more noise on each pixel, then you should increase the variance. If you mean the amount of pixels that have noise added to them, then you can make a random bool matrix with the percentage and select from the noised image.

mask = rand (size (image)) < 0.5; # percentage of pixels to have noise
noised = image;
noised(mask) = imnoise (image, "gaussian")(mask);

If by percentage of noise you mean ammount of "lost pixels", then try to use the salt and pepper option.

noise = imnoise (image, "salt and pepper", percentage);

Upvotes: 2

Related Questions