Code covered by the BSD License  

Highlights from
Robust spline smoothing for 1-D to N-D data

4.69231

4.7 | 13 ratings Rate this file 132 Downloads (last 30 days) File Size: 6.52 KB File ID: #25634
image thumbnail

Robust spline smoothing for 1-D to N-D data

by Damien Garcia

 

22 Oct 2009 (Updated 11 Apr 2012)

SMOOTHN allows automatized and robust smoothing in one and higher dimensions w/wo missing values

| Watch this File

File Information
Description

SMOOTHN provides a fast, unsupervised and robust discretized spline smoother for data of any dimension.

SMOOTHN(Y) automatically smoothes the uniformly-sampled array Y. Y can be any N-D noisy array (time series, images, 3D data,...).

SMOOTHN can deal with missing (NaN) values (see screenshot, top panels).

SMOOTHN(...,'robust') carries out a robust smoothing that minimizes the influence of outlying data (see screenshot, bottom right panel).

SMOOTHN is made automated by the minimization of the generalized cross-validation score.

Enter "help smoothn" in the Matlab command window for complete instructions and 1-D to 3-D examples.

------
Here is an example that requires the Image Processing Toolbox. The example below applies SMOOTHN to an image of Saturn that has had Gaussian noise added.

% Read the "Saturn" image from Matlab
I = rgb2gray(imread('saturn.png'));

% Add Gaussian noise to the image
J = imnoise(I,'gaussian',0,0.025);

% Remove the noise using the SMOOTHN function.
% Let SMOOTHN choose the amount of smoothness automatically
K = smoothn(J);
K = uint8(K); % back to 8-bit integer format

% Now check the result
subplot(121), imshow(J), title('Noisy Saturn')
subplot(122), imshow(K), title('Denoised Saturn')

------
Other 1-D to 3-D examples are given in:
http://www.biomecardio.com/matlab/smoothn.html
-----
For details about the algorithm, refer to:
http://www.biomecardio.com/pageshtm/publi/csda10.pdf
-----

Acknowledgements
This submission has inspired the following:
Post-processing of PIV data, PIVlab - time-resolved particle image velocimetry (PIV) tool
MATLAB release MATLAB 7.5 (R2007b)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (15)
23 Oct 2009 Carlos Adrian Vargas Aguilera

Welcome back!

30 Oct 2009 Xianmin

Good job!

31 Oct 2009 Jan Simon

H1 line, really descriptive help, examples, date and author mentioned, comments in the code, referenced method, and finally it works well.

15 Jan 2010 Rob Campbell

This is nice!

18 Jan 2010 Mark Shore

Definitely very interesting looking. Well referenced with a range of 1, 2 and 3D examples, which work quite well. I'll rate this once I've had a chance to look at it in more detail.

However the author should correct the required products listing since the image processing toolbox is NOT a requirement per se. All of the provided test examples work perfectly without it. A call to bwdist to replace NaNs in supplied data defaults gracefully to another option if the image processing toolbox is not installed. And rgb2gray and imnoise are required only to _create_ the example of the noisy Saturn image given above, not to denoise it.

It would also be convenient for the author to include his subroutines dctn.m and idctn.m in the FEX file if possible, rather than requiring a separate download from an external web site.

21 Feb 2010 Mark Shore  
20 Apr 2010 Matthew Souders

Code does not work out of the box for MATLAB 7.1 - at least I was unable to get it to function. Attempted a test case and got this error:

??? Undefined function or method 'bsxfun' for input argument of type 'function_handle'.

Error in ==> smoothn at line 266
    Lambda = bsxfun(@plus,Lambda...

If some special set-up is required to make this code run successfully, this needs to be carefully documented.

20 Apr 2010 Damien Garcia

to Matthew: you should have read the File description:
MATLAB release: MATLAB 7.5 (R2007b)
BSXFUN is nonexistent in versions prior to 7.4!
Regards. DG

13 Jun 2010 Warwick

Very good!. Minor effort to obtain dctn and idctn but this is an easy way to smooth out "zigzag" contours (much better than going with INTERP2( Array, ntimes)).
thank you.

05 Jul 2010 Juha-Matti Alakoskela  
09 Aug 2010 Balengi

I like this function very much...I do have a question though. I am smoothing a 50x50x3 n-d array but after smoothing my 3-d object is much flatter than the original. it almost seems distorted...has this ever happened to you before?

08 Dec 2010 Richard

Well done! well documented. very easy to use.
Richard

18 May 2011 Erik

Really nice method!

I does seem to me though that there is a bug when using this in combination with your pppiv-function.

In the function RobustWeights, there is a line:
MAD = median(abs(r(I)-median(r(I))));

However, the values of r are complex when using it together with pppiv. That causes the median function to sort the values by the real component and then take the middle value. I think you probably want to add
r = abs(r);
before taking the median to sort the residuals by magnitude instead. Is that correct?

23 Feb 2012 Erdal Bizkevelci  
09 May 2012 Jakub Wosyka

Hello Damien,
very useful and nice function.
I tried to add the non-uniform grid (x values) according to your article but then it only interpolates the data. When I raise the value of smooting parameter, new the function will fall to zero (zero mean). (...probably my fault...). Do you plan to extend this nice function for non-uniform grids? Thank you

Please login to add a comment or rating.
Updates
30 Oct 2009

An example has been added

17 Nov 2009

The "upsample" option has been removed

07 Dec 2009

Very much faster now with weighted/missing data:
1) SOR
2) Initial guess from nearest-neighbor interpolation
3) GCV score is minimized every 2^k iterations (k = 0...)

17 Dec 2009

A bug has been reported with a smoothness parameter input. Thank you B.S.

15 Jan 2010

The link to the manuscript has been modified.

19 Jan 2010

Gamma was undefined when "isauto" variable was false.

27 Jan 2010

A minor bug in error(nargchk(...))

25 Feb 2010

Minor modification in the relaxation factor

26 Apr 2010

fix a minor bug with the warning messages

10 Jun 2010

Some options have been removed/added

08 Nov 2010

minor modifications: mlint messages removed

23 Nov 2011

3 optional weighting functions

25 Nov 2011

3 optional weighting functions

11 Apr 2012

some typos

Tag Activity for this File
Tag Applied By Date/Time
image processing Damien Garcia 23 Oct 2009 10:34:07
signal processing Damien Garcia 23 Oct 2009 10:34:08
statistics Damien Garcia 23 Oct 2009 10:34:08
smooth Wolfgang Schwanghart 18 Nov 2009 03:06:56

Contact us at files@mathworks.com