How to remove gaussian noise?

Hello, I'm working on image encryption. I need to see how well my encryption is so i thght of adding noise and testing it.I added gaussian noise with the following code.My problem is i dont know how to remove it before applying decryption algorithm.i get decimal values, I want to get whole numbers in the resulting matrix.
I=imread('leena.bmp');
M =0;
V=0.01;
imshow(I);
title('Original Image');
J = imnoise(I,'gaussian',M,V);
gure,imshow(J);
title('Gaussian Noise');
i'm planning to add other noises as well like poisson noise, speckle noise and salt and pepper noise. Is there any possibility that a code exists for removing all these noises separately? please help..thanks in advance

2 Comments

What is M and V mean?
Did you look up imnoise() in the help? M is the mean and V is the variance. From the help:
J = imnoise(I,'gaussian',m,var_gauss) adds Gaussian white noise with mean m and variance var_gauss.

Sign in to comment.

 Accepted Answer

For Gaussian noise, the maximum likelihood de-noised answer would just be a local mean, which you can do with conv2():
denoisedImage = conv2(double(noisyImage), ones(3)/9, 'same');
If you want to do Salt and Pepper noise, then see my attached demos where I use a modified median filter.

12 Comments

thank u so much sir. May i know why we use ones(3)/9 and 'same'.
ones gives a 3 by 3 local window where it multiplies each element of that by the value of the image when it's over that part of the image. Then it slides along to the next location until it's scanned the whole image. 'same' makes the output image be the same size as the input image, otherwise it's larger because it's possible for just one row or column of the window to overlap the image when it's positioned at the last row or column. This is the "edge effect" or "boundary effect".
Abirami
Abirami on 1 Nov 2014
Edited: Abirami on 1 Nov 2014
sir but the resulting image has decimal values. how do i convert them to whole numbers so that i carry out the decryption.the image im using is a 256x256 greyscale image. please help...thanks in advance.
denoisedImage = uint8(denoisedImage);
thank u so much sir...
i got error while using
for my gray image
Error using medfilt2
Expected input number 1, A, to be two-dimensional.
Error in medfilt2>parse_inputs (line 107)
validateattributes(a, ...
Error in medfilt2 (line 49)
[a, mn, padopt] = parse_inputs(args{:});
Error in salt_and_pepper_noise_removal_grayscale (line 40)
medianFilteredImage = medfilt2(noisyImage, [3 3], 'syimmetric');
Looks like your gray image is actually an RGB image. It may look gray but it has 3 color channels, so probably all three channels are identical. Try this:
if ndims(grayImage) > 1
grayImage = grayImage(:, :, 1);
end
If that still doesn't work, attach your script and image so I can fix it.
agung pratama
agung pratama on 7 Aug 2020
Edited: agung pratama on 7 Aug 2020
Thanks, this is the image i attach here, because i still got error
agung, you have to put in that code after you read in gray image. See attached.
Thakhs Image Analyst,
Can you explaine to me [3 3] means in
medianFilteredImage = medfilt2(noisyImage, [3 3]);
If you check the documentation you'll see that it's the window size of the window that scans across the image.
Thanks Image Analyst, have a good day

Sign in to comment.

More Answers (1)

lakpa tamang
lakpa tamang on 15 Dec 2019
Image Analyst.. can you explain how does the denoising works actually.. mathamatically?

3 Comments

It depends on the algorithm but essentially it tries to determine what is noise and what is signal at that point, and replace the actual value with the signal-only value. Different algorithms make different assumptions on what is noise and what is signal.
Image analyst , I am trying to excute the last file of
But I am getting error : salt_and_pepper_noise_removal_grayscale
Undefined function or variable 'salt_and_pepper_noise_removal_grayscale'.
Please do help
How are you trying to run it? Is it open in the editor window? Did you click the green run triangle? Then it will run. I just ran it again to make sure everything works fine, and it does.

Sign in to comment.

Categories

Community Treasure Hunt

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

Start Hunting!