-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnt_multismooth_old.m
executable file
·54 lines (47 loc) · 1.5 KB
/
nt_multismooth_old.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
function z=nt_multismooth(x,smooth,alignment,diff_flag)
%z=nt_multismooth(x,smooth,alignment,diff_flag) - apply multiple smoothing kernels
%
% y: result
%
% x: matrix to smooth
% smooth: vector of smoothing kernel sizes
% alignment: -1: left [default], 0: center
% diff_flag: if true, return 1sr colum & between-column differences
%
% X is smoothed column by column (all smoothed versions of 1st column, then all
% of second column, etc).
%
% X may be 1D, 2D or 3D. See also nt_multishift.
%
% NoiseTools
nt_greetings;
if nargin<4 || isempty(diff_flag); diff_flag=0; end
if nargin<3 || isempty(alignment); alignment=-1; end
if nargin<2; error('!'); end
if min(smooth)<1; error('smooth must be positive'); end
if iscell(x)
for iCell=1:length(x);
z{iCell}=nt_multismooth(x{iCell},smooth,alignment);
end
return
end
if size(x,1)<max(smooth); error('smoothing kernel size should be no larger than nrows'); end
if min(smooth)<0; error('smoothing kernel size should be nonnegative'); end
smooth=smooth(:)';
nsmooth=numel(smooth);
% array of shift indices
[m,n,o]=size(x);
z=zeros(m,n*nsmooth,o);
for iPage=1:o
zz=zeros(m,n,nsmooth);
for iSmooth=1:nsmooth
if alignment==-1; nodelayflag=0; elseif alignment==0; nodelayflag=1; else; error('!!'); end
zz(:,:,iSmooth)=nt_smooth(x(:,:,iPage),smooth(iSmooth),[],nodelayflag);
end
if diff_flag
zz=cat(3,zz(:,:,1),diff(zz,[],3));
end
zz=permute(zz,[1,3,2]);
zz=reshape(zz,m,n*nsmooth);
z(:,:,iPage)=zz;
end