-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathsmooth3D.m
108 lines (82 loc) · 1.9 KB
/
smooth3D.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
function smoothedImage=smooth3D(image,smoothradius, ResolutionX, ResolutionY, ResolutionZ,displaywaitbar)
%Smooth image in 3D
%Einar Heiberg
if nargin<6
displaywaitbar = false;
end;
XSize=size(image,1);
YSize=size(image,2);
TSize=size(image,3);
ZSize=size(image,4);
timeframes=1:TSize;
%smoothing filter
n = 9;
%X direction
x = linspace(-n*ResolutionX,n*ResolutionX,2*n+1);
f = exp(-(x.^2)/(smoothradius.^2));
f = f./sum(f(:));
f = single(f);
fx = f(:);
%Y direction
x = linspace(-n*ResolutionY,n*ResolutionY,2*n+1);
f = exp(-(x.^2)/(smoothradius.^2));
f = f./sum(f(:));
f = single(f);
fy = f(:)';
%Z direction
x = linspace(-n*ResolutionZ,n*ResolutionZ,2*n+1);
f = exp(-(x.^2)/(smoothradius.^2));
f = f./sum(f(:));
f = single(f);
fz = reshape(f,[1 1 length(f)]);
%smooth
%temp=repmat(single(0),[XSize YSize TSize ZSize]);
if displaywaitbar
h = waitbar(0,'Please wait.');
end;
%Create output
temp = single(0)*single(image);
if displaywaitbar
h = waitbar(0.1,h);
end;
if ZSize>1
%Smooth in x-dir
for tloop=timeframes
temp(:,:,tloop,:) = econv3(...
single(squeeze(image(:,:,tloop,:))),fx);
end;
if displaywaitbar
h = waitbar(0.4,h);
end;
%Smooth in y-dir
for tloop=timeframes
temp(:,:,tloop,:) = econv3(squeeze(temp(:,:,tloop,:)),fy);
end;
if displaywaitbar
h = waitbar(0.7,h);
end;
%Smooth in z-dir
for tloop=timeframes
temp(:,:,tloop,:) = econv3(squeeze(temp(:,:,tloop,:)),fz);
end;
if displaywaitbar
h = waitbar(1,h);
end;
else
%Smooth in x-dir
temp = econv3(...
single(squeeze(image)),fx);
if displaywaitbar
h = waitbar(0.55,h);
end;
%Smooth in y-dir
temp = econv3(squeeze(temp),fy);
if displaywaitbar
h = waitbar(1,h);
end;
end
%Store output
smoothedImage=temp;
if displaywaitbar
close(h);
end;