File Exchange

image thumbnail

Non-Local Means Filter

version 1.0 (2.22 KB) by

Non-Local Means Filter for image denoising

3.69231
22 Ratings

119 Downloads

Updated

View License

Implementation of the Non-Local Means Filter proposed by Buades et al. for robust image denoising.

typical usage:

fima=nlmeans(ima,5,2,sigma);

being sigma the noise standard deviation

Comments and Ratings (38)

Nina

Nina (view profile)

 d = sum(sum(kernel.*(W1-W2).*(W1-W2)));
 w=exp(-d/h); % the h was replaced by h*h in the line32

Aman Sharma

d = sum(sum(kernel.*(W1-W2).*(W1-W2)));
This line throws an error.
"Error using ==> times
Integers can only be combined with integers of the same class, or scalar doubles."
How do we rectify that?

lynnea lin

I doubt if it should be
 d = sqrt(sum(sum(kernel.*(W1-W2).*(W1-W2))));
 w=exp(-d/(h*h));
not
 d = sum(sum(kernel.*(W1-W2).*(W1-W2)));
 w=exp(-d/h);
??

521

521 (view profile)

chao zhang

I have a great hope to download the code justnow, i wish it will give me great help!

chao zhang

Jing Hu

Thanks for the contribution, Jose.

li teng

Tarun Katyal

for i=1:m
 for j=1:n
                 
         i1 = i+ f;
         j1 = j+ f;
                
         W1= input2(i1-f:i1+f , j1-f:j1+f);
         
         wmax=0;
         average=0;
         sweight=0;
         
         rmin = max(i1-t,f+1);
         rmax = min(i1+t,m+f);
         smin = max(j1-t,f+1);
         smax = min(j1+t,n+f);
         
         for r=rmin:1:rmax
         for s=smin:1:smax
                    
                if(r==i1 && s==j1) continue; end;
                    
                W2= input2(r-f:r+f , s-f:s+f);

could someone explain how are these W1 and W2 points calculated??
plz help not able to understand the code

John

John (view profile)

I believe there is a bug in this code. If you change the line in demo.m, to display the error between the filtered and original images, i.e. from:

subplot(2,2,4),imagesc(rima-fima),title('residuals');

to

subplot(2,2,4),imagesc(ima-fima),title('residuals');

There is a clear bias/issue with the lower left hand quadrant edges, but not with the upper right hand quadrant edges.

selma

selma (view profile)

thanks for helping us

Prabhakar

Suggest me how to give external image by applying this code

sadaiyandi

max(a,b)
what is the return type its array or int value i am getting trouble when i am implementing in java

Zhang Xuande

cool!!

YoonOh Tak

YoonOh Tak (view profile)

Is this line right?

fima=NLmeansfilter(ima,5,2,sigma);

I think it has to change like below

fima=NLmeansfilter(rima,5,2,sigma);

i have the same doubt what crisitna asked. can you help me. can u send me the modified codings

Royi Avital

Hello.
You mention to have the "Original" version which is slower yet easier to understand,
Where can I find it?
Thanks.

Tai Fei

Hi, Jose, I have 2 questions on the kernel.
1). Is it gaussian kernel which is mentioned in the paper of Buades. As far as i know, the one in your code is not gaussian.
2). why you take these two steps ?
average = average + wmax*input2(i1,j1);
        sweight = sweight + wmax;

I cannot find any ground in the original paper, but it does make my algorithm oscillate less. could you give me some idea, why you make them ?

Victor Lee

Hi Jose, you've mention of the bug earlier on but I can't seem to find it. Is it rectified and updated?

how to calculate sigma, h and f? I am confused. I am a student, need urgent help. u can also email me at abhishek85bansal@gmail.com

Haoheng Zheng

Good, but few notation...

Vijay

Vijay (view profile)

Performance of the algorithm will depend on the sigma estimation in noisy image. How to estimate good sigma?

cristina

I must define input,f,t,h...I'm not sure that I know how!
Can you help me please?I'm a beginer in matlab...thank you!

cristina

I have a little error here [m n]=size(input); in NLmeansfilter.m:

> NLmeansfilter
??? Input argument 'input' is undefined.

Error in ==> C:\Documents and Settings\Iulia\Desktop\matlab\NLmeansfilter.m
On line 19 ==> [m n]=size(input);

I need help...Thanks!

Jose Manjon

You are right Bi Yiming.

Sorry about that.

Jose

Bi Yiming

i think it should be
 fima=NLmeansfilter(rima,5,2,sigma);
not fima=NLmeansfilter(ima,5,2,sigma);
in demo.m

Kevin Verghese

d = sum(sum(kernel.*(W1-W2).*(W1-W2)));
This line throws an error.
"Error using ==> times
Integers can only be combined with integers of the same class, or scalar doubles."
How do we rectify that?

Jose Manjon

You have to use sigma, not 10*sigma

being signa the image noise standard deviation

Jose

Roger Ting

How to set the sigma for the algorithm.I chose 10*noisesigma, the result is very bad.

Reza Farrahi Moghaddam

Good Work,

Only, please change the word "radio" to "size" (in the definitions of "t" and "f")

Thanks

victor diaz

Jose Manjon

The original code was not optimized to easily understand the filter caracteristics. Now, I have already vectorized it to speed up the filter. New version is much faster but if you plan to use it rutinarily I suggest you to mex it.

Peter L

It is really slow. You need to vectorize it.

Jose Manjon

There is a small bug in the code, please
chage:
 
k=max(abs(i),abs(j));

for

k=max([abs(i),abs(j),1]);

enjoy the filter

Jose Manjon

James Chan

cool

Updates

I have vectorized it to speed up the filter

MATLAB Release
MATLAB 7.0.1 (R14SP1)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video