How to remove gaussian noise from an image in MATLAB?
Asked Answered
C

3

6

I'm trying to remove a Gaussian noise from an image. I've added the noise myself using:

nImg = imnoise(img,'gaussian',0,0.01);

I now need to remove the noise using my own filter, or at least reduce it. In theory, as I understand, using a convolution matrix of ones(3)/9 should help and using a Gaussian convolution matrix like [1 2 1; 2 4 2; 1 2 1]/9 or fspecial('gaussian',3) should be better. Yet, they really don't do the trick so well: enter image description here

Am I missing something important? I need to use convolution, by the way.

Crenel answered 23/12, 2011 at 17:54 Comment(2)
The averaging filter (your "ones" filter) is a bad low-pass filter. The gaussian is a better LPF. The reason you are getting distortion on the 1 2 1; 2 4 2; 1 2 1 filter is because it isn't normalized properly.Dell
You're right about the 1 2 1;2 4 2;1 2 1. I should have divided by 16 and not by 9. Even so, it's not working too well: linkCrenel
A
10

You are not missing anything! Obviously, you can't remove the noise completely. You can try different filters, but all of them will have a tradeoff:

More Noise + Less blur VS Less Noise + More blur

It becomes more obvious if you think of this in the following way:

Any convolution based method assumes that all of the neighbors have the same color.

But in real life, there are many objects in the image. Thus, when you apply the convolution you cause blur by mixing pixels from different adjacent objects.

There are more sophisticated denoising methods like:

  • Median denoising
  • Bilateral filter
  • Pattern matching based denoising

They are not using only convolution. By the way, even they can't do magic.

Amsden answered 23/12, 2011 at 18:12 Comment(5)
Thanks. I've seen that tradeoff during implementation and I've also implemented median denoising which works great for salt&pepper noise but not so much for Gaussian noise. Still, how can I find the thin boundary between an image that is too noisy but sharp and an image that is too blurry but with a little noise? I have a few parameters to play with: Matrix dimensions (small, large, square, rectangular) and matrix values (Gaussian, uniform, some other weird setting). So, is there really nothing decent I can do with just convolution?Crenel
@shwartz, unfortunately, not. You need at least some kind of logic that will detect edges, corners, etc and will treat them accordingly. Which isn't only convolution by definition.Amsden
Actually, that's kind of encouraging since the assignment is to use convolution (solely, as I understand). Only problem is to find a "good" method and how to know which result is best. Is there any way to quantify the quality of the result? For example, will some sort of matrix distance from the original noise-less image be a good way to determine the quality of my result? Or is there some other common method?Crenel
I suggest that you ask another question on the subject :) You can put a link to this one.Amsden
@Andrey I am interested in what you have said... should I ask a new question all together on stack exchange? What I am trying to understand is the trade off between cancelling noise, but not cancelling edges... perhaps a summary of some of those techniques. (I have come across 'ansiotropic diffusion' for example)... how do those work? What is being changed? Thanks.Feme
A
1

you can use wiener2 which works best when the noise is constant-power ("white") additive noise, such as Gaussian noise.

Ahimsa answered 7/12, 2013 at 15:18 Comment(0)
P
0

You made a mistake with the Gaussian convolution matrix. You need to divide it by 16, not 9, so that it's sum equals 1. That's why the resulting image using that matrix is so light.

Patsis answered 22/6, 2013 at 15:47 Comment(1)
Thanks, I know. Someone already commented below the original post.Crenel

© 2022 - 2024 — McMap. All rights reserved.