Adding White Gaussian noise

5 visualizzazioni (ultimi 30 giorni)
imi kh
imi kh il 18 Gen 2012
Modificato: Parag il 9 Apr 2025
Hi, I want to add white Gaussian noise at snr level of 5 db to an image, how do i add it.

Risposte (1)

Parag
Parag il 9 Apr 2025
Modificato: Parag il 9 Apr 2025
To add white Gaussian noise at an SNR level of 5 dB 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.
Here's the MATLAB implementation for that approach:
% Load sample image
img = im2double(imread('peppers.png')); % RGB image
% Compute signal power
signalPower = mean(img(:).^2);
% Set desired SNR in dB
snr_dB = 5;
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 5 dB Gaussian Noise');
Please refer to the MATLAB documentation below for more information on wgn function:
Hope this works!

Categorie

Scopri di più su Propagation and Channel Models in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by