-
Notifications
You must be signed in to change notification settings - Fork 3
/
GVFOptimizeImageForces3D.m
58 lines (48 loc) · 1.62 KB
/
GVFOptimizeImageForces3D.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
function Fext=GVFOptimizeImageForces3D(Fext, Mu, Iterations, Sigma)
% This function "GVFOptimizeImageForces" does gradient vector flow (GVF)
% on a vector field. GVF gives the edge-forces a larger capature range,
% to make the snake also reach concave regions
%
% Fext = GVFOptimizeImageForces3D(Fext, Mu, Iterations, Sigma)
%
% inputs,
% Fext : The image force vector field N x M x 3
% Mu : Is a trade of scalar between noise and real edge forces
% Iterations : The number of GVF itterations
% Sigma : Used when calculating the Laplacian
%
% outputs,
% Fext : The GVF optimized image force vector field
%
% Function is written by D.Kroon University of Twente (July 2010)
% Squared magnitude of force field
Fx= Fext(:,:,:,1);
Fy= Fext(:,:,:,2);
Fz= Fext(:,:,:,3);
% Calculate magnitude
sMag = Fx.^2+ Fy.^2 + Fz.^2;
% Set new vector-field to initial field
u=Fx; v=Fy; w=Fz;
% Iteratively perform the Gradient Vector Flow (GVF)
for i=1:Iterations,
% Calculate Laplacian
Uxx=ImageDerivatives3D(u,Sigma,'xx');
Uyy=ImageDerivatives3D(u,Sigma,'yy');
Uzz=ImageDerivatives3D(u,Sigma,'zz');
% Update the vector field
u = u + Mu*(Uxx+Uyy+Uzz) - sMag.*(u-Fx);
clear('Uxx','Uyy','Uzz');
Vxx=ImageDerivatives3D(v,Sigma,'xx');
Vyy=ImageDerivatives3D(v,Sigma,'yy');
Vzz=ImageDerivatives3D(v,Sigma,'zz');
v = v + Mu*(Vxx+Vyy+Vzz) - sMag.*(v-Fy);
clear('Vxx','Vyy','Vzz');
Wxx=ImageDerivatives3D(w,Sigma,'xx');
Wyy=ImageDerivatives3D(w,Sigma,'yy');
Wzz=ImageDerivatives3D(w,Sigma,'zz');
w = w + Mu*(Wxx+Wyy+Wzz) - sMag.*(w-Fz);
clear('Wxx','Wyy','Wzz');
end
Fext(:,:,:,1) = u;
Fext(:,:,:,2) = v;
Fext(:,:,:,3) = w;