## How to add to an image white Gaussian noise of zero mean and standard deviation of certain gray levels?

### Mohsin Shah (view profile)

on 12 Jul 2018
Latest activity Commented on by Mohsin Shah

on 13 Jul 2018

### Image Analyst (view profile)

Hello everyone, How can we add white Gaussian noise to an image with zero mean and standard deviation of 64 gray levels? I do know how to add noise of zero mean and variance using imnoise but I do not know about standard deviation of 64 gray levels.

### Image Analyst (view profile)

on 12 Jul 2018

Did you try imnoise() or randn()? If not, why not? They're so easy that you should be able to figure them out on your own.

Mohsin Shah

### Mohsin Shah (view profile)

on 13 Jul 2018
Thank you Image Analyst.
Image Analyst

### Image Analyst (view profile)

on 13 Jul 2018
OK, I sense that you tried but couldn't do it, so here is a full demo:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
% Make a gray scale image of brightness 128 gray levels.
grayImage = 128 * ones(480, 640, 'uint8');
% Make a noise image of standard deviation 64 gray levels.
noiseOnlyImage = 64 * randn(480, 640);
% Add the noise image to the gray scale image.
% Compute the standard deviation of the three images.
sdGray = std(double(grayImage(:)))
sdNoiseOnly = std(noiseOnlyImage(:))
% Compute the means of the three images.
meanGray = mean(double(grayImage(:)))
meanNoiseOnly = mean(noiseOnlyImage(:))
%======================================================
% Now plot everything.
subplot(2, 3, 1);
imshow(grayImage);
title('Original Image', 'FontSize', 20);
% Display its histogram
subplot(2, 3, 4);
imhist(grayImage);
grid on;
caption = sprintf('Histogram of Original Image\nMean = %.2f, SD = %.2f', meanGray, sdGray);
title(caption, 'FontSize', 20);
subplot(2, 3, 2);
imshow(noiseOnlyImage, []);
title('Noise-Only Image', 'FontSize', 20);
% Display its histogram
subplot(2, 3, 5);
histogram(noiseOnlyImage, 'EdgeColor', 'none');
grid on;
caption = sprintf('Histogram of Original Image\nMean = %.2f, SD = %.2f', meanNoiseOnly, sdNoiseOnly);
title(caption, 'FontSize', 20);
subplot(2, 3, 3);
% Display its histogram
subplot(2, 3, 6);