fillgap
PURPOSE 
y=fillgap(x,w,maxGapSize) - fill gaps using simple interpolation
SYNOPSIS 
function [y,w]=fillgap(x,w,maxGapSize)
DESCRIPTION 
CROSS-REFERENCE INFORMATION 
This function calls:
This function is called by:
- nt_inpaint function y=nt_inpaint(x,w) - weighted interpolation based on correlation structure
- nt_outliers [w,y]=nt_outliers(x,w,thresh) - detect outliers based on weighted correlation structure
SOURCE CODE 
0001 function [y,w]=fillgap(x,w,maxGapSize)
0002
0003
0004
0005
0006
0007
0008
0009 if nargin<2; error('!'); end
0010 if nargin<3||isempty(maxGapSize); maxGapSize=1; end
0011 if size(x,2)>1; error('!'); end
0012 if size(x) ~= size(w); error('!'); end
0013 y=x;
0014 if all(w); return; end
0015
0016 iToFix=1+find(~w(2:end-1)&w(1:end-2)&w(3:end));
0017 y(iToFix)=(y(iToFix-1)+y(iToFix+1))/2;
0018 w(iToFix)=1;
0019
0020 iStart=find(w(1:end-2) & ~w(2:end-1));
0021 iStop=find(~w(1:end-1) & w(2:end));
0022 if isempty(iStart)||isempty(iStop); return; end
0023 if iStop(1)<iStart(1);
0024 iStop=iStop(2:end);
0025 end
0026 iStart=iStart(1:numel(iStop));
0027 for gapSize=2:maxGapSize
0028 idx=find(iStop-iStart==gapSize);
0029 for k=1:gapSize
0030
0031 y(iStart(idx)+k) = ( y(iStart(idx)) * (gapSize-k+1) + y(iStart(idx)+gapSize+1) * k ) / (gapSize+1);
0032 w(iStart(idx)+k) = 1;
0033 end
0034 end
Generated on Tue 09-May-2017 13:19:57 by m2html © 2005