Code covered by the BSD License  

Highlights from
Inpaint over missing data in N-D arrays

5.0

5.0 | 5 ratings Rate this file 43 Downloads (last 30 days) File Size: 3.56 KB File ID: #27994
image thumbnail

Inpaint over missing data in N-D arrays

by Damien Garcia

 

23 Jun 2010 (Updated 25 Jun 2010)

Y = INPAINTN(X) replaces the missing data in X by extra/interpolating the non-missing elements.

| Watch this File

File Information
Description

Y = INPAINTN(X) replaces the missing data in X by extra/interpolating the non-missing elements. The non finite values (NaN or Inf) in X are considered as missing data. X can be any N-D array.
 
Important note:
----------------
INPAINTN uses an iterative process that converges toward the solution. Y = INPAINTN(X,N) uses N iterations. By default, N = 100. If you estimate that INPAINTN did not totally converge, then increase N: Y = INPAINTN(X,1000);

Notes:
-----
INPAINT_NANS and INPAINT_NANS3 are faster than INPAINTN when the number of NaN elements is (relatively) small. However, because INPAINT_NANS and INPAINT_NANS3 both involve huge matrices, they can be limited with large datasets.
 
Example:
--------
%% ---- 3-D data ---- %%
load wind
xmin = min(x(:)); xmax = max(x(:));
zmin = min(z(:)); ymax = max(y(:));
%-- wind velocity
vel0 = interp3(sqrt(u.^2+v.^2+w.^2),1,'cubic');
x = interp3(x,1); y = interp3(y,1); z = interp3(z,1);
%-- remove randomly 90% of the data
I = randperm(numel(vel0));
velNaN = vel0;
velNaN(I(1:round(numel(I)*.9))) = NaN;
%-- inpaint using INPAINTN
vel = inpaintn(velNaN);
%-- display the results
subplot(221), imagesc(velNaN(:,:,15)), axis equal off
title('Corrupt plane, z = 15')
subplot(222), imagesc(vel(:,:,15)), axis equal off
title('Reconstructed plane, z = 15')
subplot(223)
hsurfaces = slice(x,y,z,vel0,[xmin,100,xmax],ymax,zmin);
set(hsurfaces,'FaceColor','interp','EdgeColor','none')
hcont = contourslice(x,y,z,vel0,[xmin,100,xmax],ymax,zmin);
set(hcont,'EdgeColor',[.7,.7,.7],'LineWidth',.5)
view(3), daspect([2,2,1]), axis tight
title('Original data compared with...')
subplot(224)
hsurfaces = slice(x,y,z,vel,[xmin,100,xmax],ymax,zmin);
set(hsurfaces,'FaceColor','interp','EdgeColor','none')
hcont = contourslice(x,y,z,vel,[xmin,100,xmax],ymax,zmin);
set(hcont,'EdgeColor',[.7,.7,.7],'LineWidth',.5)
view(3), daspect([2,2,1]), axis tight
title('... reconstructed data')

------
http://www.biomecardio.com
-----

Acknowledgements

The author wishes to acknowledge the following in the creation of this submission:
inpaint_nans, Inpainting nan elements in 3-d

MATLAB release MATLAB 7.6 (R2008a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (5)
29 Jul 2010 Leonardo

Very useful, works nicely. The only issue is that a couple of additional functions (dctn and idctn) have to be downloaded from another site for this to work

12 Oct 2010 Bohuslav Ruzek

I had to interpolate missing 3D geophysical data in order to enable standard filtration process. Inpaint code worked very well for this, the results look pretty well. Using inpaint is easy.
I recommend using this script also for other interested users.

08 Nov 2011 tudor dima

Great work, extremely useful, it works out of the box.
Thanks a lot for posting it!

Would there be a simple way to restrict calculations inside a "gating mask"?

01 Mar 2012 Kyle  
01 Mar 2012 Kyle

Very useful script. I will never use matlab extrapolation routines ever again.

Please login to add a comment or rating.
Updates
24 Jun 2010

Image toolbox is no longer required.

25 Jun 2010

1) there was a mistake in the 4-D example
2) an initial guess can be now given as an input

Tag Activity for this File
Tag Applied By Date/Time
inpaint Damien Garcia 23 Jun 2010 12:03:04
griddatan Damien Garcia 23 Jun 2010 12:03:04
interpolation Damien Garcia 23 Jun 2010 12:03:04
extrapolation Damien Garcia 23 Jun 2010 12:03:04
image processing Damien Garcia 23 Jun 2010 12:03:04
missing data Damien Garcia 23 Jun 2010 12:03:04
inpainting nan elements in 3d xiuhong 28 Mar 2012 22:21:00
missing data TA 19 Apr 2012 15:36:13

Contact us at files@mathworks.com