imnoise gaussian noise clarification
Categories:
Understanding Gaussian Noise in MATLAB's imnoise
Function

Clarify the parameters and behavior of Gaussian noise generation using MATLAB's imnoise
function, focusing on standard deviation and variance.
Adding noise to images is a common operation in image processing for simulating real-world sensor imperfections, testing algorithm robustness, or data augmentation. MATLAB's imnoise
function is a versatile tool for this purpose, offering various noise types, including Gaussian noise. However, the interpretation of its parameters, specifically for Gaussian noise, often leads to confusion regarding standard deviation and variance. This article aims to demystify these parameters and provide a clear understanding of how imnoise
generates Gaussian noise.
Gaussian Noise Fundamentals
Gaussian noise is a statistical noise that has a probability density function (PDF) equal to that of the normal distribution, also known as the Gaussian distribution. It is characterized by its mean (average value) and variance (spread of values). In image processing, Gaussian noise typically adds random values drawn from a Gaussian distribution to each pixel's intensity. The imnoise
function in MATLAB allows you to specify these characteristics.
flowchart TD A[Input Image] --> B{imnoise('gaussian', M, V)} B --> C[Generate Random Numbers from N(M, V)] C --> D[Add Noise to Image Pixels] D --> E[Output Noisy Image] subgraph Gaussian Noise Parameters M[Mean (M)] V[Variance (V)] end B -- Specifies --> M B -- Specifies --> V
Flowchart illustrating the process of adding Gaussian noise using imnoise
.
The imnoise
Function for Gaussian Noise
When using imnoise
to add Gaussian noise, the syntax is typically J = imnoise(I, 'gaussian', M, V)
, where I
is the input image, J
is the output noisy image, M
is the mean of the Gaussian distribution, and V
is the variance of the Gaussian distribution. It's crucial to understand that V
represents the variance, not the standard deviation. Many users mistakenly provide the standard deviation, leading to unexpected noise levels.
% Load an example image
I = imread('cameraman.tif');
I = im2double(I); % Convert to double for accurate noise addition
% Define Gaussian noise parameters
mean_noise = 0; % Mean of the Gaussian distribution
variance_noise = 0.01; % Variance of the Gaussian distribution
% Add Gaussian noise
J = imnoise(I, 'gaussian', mean_noise, variance_noise);
% Display original and noisy images
figure;
subplot(1,2,1), imshow(I), title('Original Image');
subplot(1,2,2), imshow(J), title(sprintf('Noisy Image (Mean=%.2f, Variance=%.2f)', mean_noise, variance_noise));
MATLAB code demonstrating the addition of Gaussian noise using imnoise
with specified mean and variance.
imnoise
is the variance (V), not the standard deviation (sigma). If you intend to use a standard deviation sigma
, you must calculate the variance as sigma^2
.Relationship Between Standard Deviation and Variance
In statistics, the standard deviation (often denoted by (\sigma)) is the square root of the variance ((\sigma^2)). Both measure the spread or dispersion of a set of data points around their mean. While standard deviation is in the same units as the data, variance is in squared units. imnoise
expects the variance directly for Gaussian noise. If you have a desired standard deviation, you must square it before passing it to the function.
% Desired standard deviation
desired_std_dev = 0.05;
% Calculate the corresponding variance
calculated_variance = desired_std_dev^2;
% Add noise using the calculated variance
I = imread('cameraman.tif');
I = im2double(I);
J_std_dev = imnoise(I, 'gaussian', 0, calculated_variance);
figure;
subplot(1,2,1), imshow(I), title('Original Image');
subplot(1,2,2), imshow(J_std_dev), title(sprintf('Noisy Image (Std Dev=%.2f)', desired_std_dev));
Example of converting a desired standard deviation to variance for imnoise
.
imnoise
, it's often good practice to convert your image to double
(e.g., im2double(I)
) before adding noise, especially if the noise parameters are small. This prevents clipping of pixel values and ensures the noise is applied accurately across the full dynamic range.