Adding White Gaussian Noise to an Image.

3 views (last 30 days)
Toqeer Mahmood
Toqeer Mahmood on 12 May 2015
Answered: Image Analyst on 9 Apr 2025
I want to put White Gaussian Noise into the target images, then after I have to analyze the Image/s have noise. The possible SNR value may by 10dB, 20dB, 30db etc.
Can anyone please explain how we can do this in MATLAB?

Answers (2)

Parag
Parag on 9 Apr 2025
To add white Gaussian noise to an image, first calculate the signal power of the image. Then, convert the desired SNR to noise power and generate noise using MATLAB’s “wgn” function for each color channel. The generated noise is added to the image, and the result is clipped to the [0,1][0, 1][0,1] range to maintain valid pixel intensities. This method provides precise control over the noise level and works well for both grayscale and RGB images.
% Load sample image
img = im2double(imread('peppers.png')); % RGB image
% Compute signal power
signalPower = mean(img(:).^2);
% Set desired SNR in dB
rand_snr = [10 20 30];
snr_dB = rand_snr(randi([1,3] , 1,1));
snr_linear = 10^(snr_dB/10);
% Compute noise power, ensuring it's non-negative
noisePower = max(signalPower / snr_linear, 0);
% Generate WGN for each channel using 'power' in dB mode
[M, N, C] = size(img);
noise = zeros(size(img));
for c = 1:C
noise(:,:,c) = wgn(M, N, 10*log10(noisePower), 'dBW'); % Use 'dBW' for dB input
end
% Add noise and clip values
noisy_img = img + noise;
noisy_img = max(min(noisy_img, 1), 0);
% Display results
figure;
subplot(1,2,1); imshow(img); title('Original Image');
subplot(1,2,2); imshow(noisy_img); title('Image with Gaussian Noise');
Please refer to the MATLAB documentation below for more information on “wgn” function:
Hope it helps!

Image Analyst
Image Analyst on 9 Apr 2025

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!