Code covered by the BSD License  

Highlights from
Fast Non-Local Means 1D, 2D Color and 3D

4.55556

4.6 | 15 ratings Rate this file 135 Downloads (last 30 days) File Size: 29.4 KB File ID: #27395
image thumbnail

Fast Non-Local Means 1D, 2D Color and 3D

by

 

28 Apr 2010 (Updated )

NL-means image and signal denoising filter based on similarity between pixel patches

| Watch this File

File Information
Description

 This function NLMF performs Non-Local Means noise filtering of 1D signal, 2D grey/color or 3D image data. The function is partly c-coded for cpu efficient filtering. Suitable for almost every image data type such as MRI, CT and normal photos.

Warning !, Image filtering removes noise, but important (medical) details can also be lost, (see discussion in comments).
 
Principle NL-Mean filter:
 A local pixel region (patch) around a pixel is compared to patches of pixels in the neighbourhood (or in the whole image). The centerpixels of the patches are averaged depending on the quadratic pixel distance between the patches.
 
 Function:
    J = NLMF( I, Options);
  inputs,
    I : 1D signal, 2D grey/color or 3D image data, of type Single or Double in range [0..1]
    Options : Struct with options, such as filtering strength
  outputs,
    J : The NL-means filtered image or image volume
 
Function(2):
     J = NLMF2Dtree(I, Options);
Same as NLMF but will search for the best matches in the whole 2D images using a kd-tree (is still extremely slow)

Literature:
- Non local filter proposed for A. Buades, B. Coll and J.M. Morel "A non-local algorithm for image denoising"
- Basic Matlab implementation of Jose Vicente Manjon-Herrera
 

MATLAB release MATLAB 7.10 (R2010a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (25)
17 Oct 2014 Renee Fang

More update:
The run the 3D example, the same thing should be done to vectors_nlmeans_single.c and image2vectors_double.c.
Replace Vsize[2] to Vsize[3] in all definitions.

17 Oct 2014 Renee Fang

The toolbox is good and fast. But the reason I gave 4-star is because it crashed when I first ran the toolbox. After reading the reviews and fixed the bugs, it is running well now.
Solution for crashing:
- In vectors_nlmeans_double.c, line 256: change Vsize[2] to Vsize[3]
- In image2vectors_double.c, line 166 & 227: change Vsize[2] to Vsize[3].

Then it works!

For those using MATLAB 2013 or higher, if there is an error "char16_t" is not recognized
Solution:
Add

#include <stdint.h>
#define char16_t UINT16_T

before #include "mex.h" in every .c file.

22 Jul 2014 xueyou

将vectors_nlmeans_double.c 256行的vsize[2]改成3,可以运行

21 Jul 2014 xueyou

Matlab crashes when run the program

28 Dec 2012 Ben

Thanks for sharing. It works very well!

17 Oct 2012 Berkin Bilgic  
02 Nov 2011 Aksam Iftikhar

Dear Author, Thanx for sharing. But, there is some error in C files as it crashes on Matlab R2010b. Ole Buus & Jancc Chan had also the same problem, but you didn't respond to them.
Please correct the error and upload correct files

03 May 2011 Ole Buus

Hi Dirk-Jan,

Is there an error in the .c files? It seems that the mex-compiler gives a warning when compiling. In line 183 in the image2vectors-files and in line 273 in the nlmeans-files. Why is Vsize only defined with dimension 2? You obviously use a third indice in those lines. I corrected the declaration of Vsize and the code compiles and even runs (before I had MATLAB crashing).

Denoised an image of 240x240 px in ~5s (Windows 7, MATLAB r2009b). It seems to work...

02 Dec 2010 IOCAS Shen

Hi, I tried this program on my Matlab R2009a, it either lost response or just exited my MATLAB, what's the problem?

06 Nov 2010 Eric Diaz

Hi SamSam,

I just wanted to say that I have nothing against Dirk-Jan. I applaud him for his work and the contributions he has made to research, programming and the matlab communities, in large. He certainly has produced excellent work in the past and generously contributed to others. I only wanted to make note of a minor or major omission (depending on how you look at it) when this file was first posted, namely a disclaimer and references. If it makes any difference, I am glad to give it another 4 star rating, even though I still haven't even tried it because I know that Dirk-Jan has put a lot of work into it and is contributing to the community.

14 Sep 2010 Dirk-Jan Kroon

*Brendan
NLM takes the mean of (the center of) image patches. In situations where the mean is not a good predictor of the real value without noise, this method will fail. It doesn't really depend on the type of noise model.

09 Sep 2010 Brendan

_Not_ an expert in this, but doesn't NLM assume additive noise? For images with multiplicative noise(e.g. SAR, CT, MRI, PET) this assumption is not valid.

22 Jul 2010 chen

OK, I am sorry for the mistaking. BTW, it there any time-cost experimental result for this implementation, × seconds for 1m image data?
Further, using the fix-point[int short byte] will run much faster(>5X) than the float-point[double float, even using the MMX/SSE1~4 instructions] .

22 Jul 2010 Dirk-Jan Kroon

*chen
I have never seen the Cuda code or paper.
(also the code may look the same from outside, but some implementation decisions are probably very different)

20 Jul 2010 chen

Nice, but the source code looks very like the C&&matlab version of "Image Denoising " example of CUDA. If so, CUDA community should get a reference at the least.

08 Jul 2010 Sam Sam

The discussion above proves to me that the old cynical joke - "No good deed ever goes unpunished" - is actually very true.

Dirk took the time to publish his very useful submission - one of 43 he's posted on Matlab Exchange - a well documented and optimized implementation of a useful algorithm, and then some jerk comes over and starts giving it one star ratings because there are no caveats for medical imaging users. If you need warnings of this sort when using medical imaging algorithms, then you suffer from some sort of blind faith in "magical software algorithms" that will de-noise everything and tell you where the tumor is 100% of the time, and need no tuning. If you don't understand what you're doing, then don't blindly apply matlab algorithms in clinical practice - you might hurt someone. It is extremely rude, in my opinion, to come here and complain about a sample algorithm implementation that someone posted just to help out fellow researchers.

Again, Dirk, great job!

13 May 2010 Stanislav  
11 May 2010 Eric Diaz

Dear Dirk,

I recommend simply removing the suggestion all together. If someone would like to venture into that territory by their own free will, then they will be liable and subject to peer review.

Alternatively, I would suggest the following amendment,

Warning !!!
Image filtering attempts to remove noise but because will end up removing some real values and replacing them with inaccurate estimates.

If tried on medical images, these artifacts are even more likely due to the different physical principles underlying image intensity at any given pixel. Please BEWARE that important anatomic and pathologic details can be lost with potentially tragic consequences. (see discussion below).

09 May 2010 Eric Diaz

Dear Dirk,

Just to let you know, I gave another rating at 1 star because I realized you only had 2 references, neither of which say anything about application to medical imaging (MRI or CT). That is very poor form!

Again, I want to say that I haven't tried your code, but I am willing to re-star your post at higher level, if you amend your opening statement to something less falsely advertising. Indeed, if you have done a good job, then you shouldn't have to sell it as more than it is. I see that you have posted many files before and so I don't doubt that you are able to code well. It is just your reckless propagation of something unscientific in such an important arena as medicine that I have problems with.

08 May 2010 Eric Diaz

Dear Dirk,

If we want to make automatic computerized recognition systems we need to use real science and not just translate what has been done in some other field and claim that it works great for medical images. Medical images are not like natural light images, they use completely different physical mechanisms to capture information.

Reconstruction needs to be performed, filtering does not. Furthermore, reconstruction is based on science fundamentally geared toward medical images to reduce bias.

I can tell you for certain that applying NLM to an MR would introduce an unacceptable amount of bias, blur the image, and cover up lesions. So what is the point? There is none. One can't just start posting up files saying they are good for this and that, when in fact they are not. Science needs to be done properly if one wants to make gains for ACRS. And thus, any medical doctor or true scientist would say that your claims and program are pointless and false with respect to medical images, as they would find the raw image better.

If you have not done your research, don't make false claims!
Propagation of unreviewed applications on the FEX to different fields is a danger to science! All you have are 2 literature citations, neither of which have anything to do with MRI or CT or any other medical imaging modality, yet you claim that it works on them!

08 May 2010 Dirk-Jan Kroon

Dear Eric Diaz,

Indeed, medical doctors are very good in recognizing small important details in raw data, and don't like filtered data.

But if we want to make an automatic computerized recognition system we need image noise filters, for fast and good image segmentation.

The filtering is indeed overdone in the example. But the amount of smoothing versus detail can be set by a simple input value.

For medical doctors is also important to there is no real "raw data". Because reconstruction of CT and MRI already contain many image filtering steps, which also have there problems, such as bias correction causing false MS lesions.

08 May 2010 Eric Diaz

Dear Dirk,

If you are not a medical doctor, I don't think you are justified in making that claim. The human eye - brain "filtering algorithm" is far more advanced than any available algorithm and does not suffer from this problem the way all other filtering algorithms do. This is why I see no reason to perform the filtering on the image in the first place, especially in the medical setting where details are important, and even much less so after knowing that it covers up lesions (again look at your image example, it is a disgrace!) . As far as there being 100+ papers on using NL-means on medical data, I can't tell you much about all modalities, but the few that I have seen in MR are awful and written by non-experts in the field. Probably attempted practical translation of some FEX NLM file, like the one you posted claiming to work miracles, by some eager person seeking a publication or fame and yet not having a clue what they are doing are talking about. I hope you can realize that there is no sound nor justified reason to make your claim, much less so knowing that someone could die from NLM covered up pathology. I hope you retract your claims and make them more reasonable.

06 May 2010 Dirk-Jan Kroon

Dear Eric Diaz,

You are right this noise filter can remove small MS lesions in MRI or other important small structures such as calcification's.

But this is the problem with all filtering algorithms, from simple Gaussian filtering to Anisotropic Diffusion Filtering.

There are 100+ papers using NL-means on Medical Data, thus my claim seems justified.

06 May 2010 Eric Diaz

Dear Dirk,

I gave this a 2 - star because it is completely false advertisement to say that this is suitable for almost every type of image, especially medical images. I would hope that a doctor doesn't miss some lesion because your code filtered it out. You should really not try to sell this as more than it is. I know that NLM is a powerful denoising algorithm but it has its limitations. Firstly, I would certainly hope that you know something about medical images, such as MRI and CT, to be making such claims. If you don't then you shouldn't be making them. I can certainly tell you from my first hand knowledge that it can cover up lesions (just look at the example picture you posted...nearly all the anatomic detail is gone!). I haven't tried your code, but I will certainly bump my stars up to at least a 4 (even without trying it, as I'm sure that you've done a decent job coding), if you amend your opening statement to something a bit more reasonable.

06 May 2010 Jancc Chan

Hi Dirk, thanks for sharing the code!

I've tried to run the code, however, my Matlab R2008b crashes all the time when I was trying the examples (I have compiled all c-code in Matlab). Can you please advice on how to solve this problem?

Many thanks!!

Updates
08 May 2010

added warning

13 May 2010

Added 1D filtering

07 Sep 2010

Added KN-tree based search

Contact us