1
+ function Fext = GVFOptimizeImageForces3D(Fext , Mu , Iterations , Sigma )
2
+ % This function "GVFOptimizeImageForces" does gradient vector flow (GVF)
3
+ % on a vector field. GVF gives the edge-forces a larger capature range,
4
+ % to make the snake also reach concave regions
5
+ %
6
+ % Fext = GVFOptimizeImageForces3D(Fext, Mu, Iterations, Sigma)
7
+ %
8
+ % inputs,
9
+ % Fext : The image force vector field N x M x 3
10
+ % Mu : Is a trade of scalar between noise and real edge forces
11
+ % Iterations : The number of GVF itterations
12
+ % Sigma : Used when calculating the Laplacian
13
+ %
14
+ % outputs,
15
+ % Fext : The GVF optimized image force vector field
16
+ %
17
+ % Function is written by D.Kroon University of Twente (July 2010)
18
+
19
+ % Squared magnitude of force field
20
+ Fx= Fext(: ,: ,: ,1 );
21
+ Fy= Fext(: ,: ,: ,2 );
22
+ Fz= Fext(: ,: ,: ,3 );
23
+
24
+ % Calculate magnitude
25
+ sMag = Fx .^ 2 + Fy .^ 2 + Fz .^ 2 ;
26
+
27
+ % Set new vector-field to initial field
28
+ u= Fx ; v= Fy ; w= Fz ;
29
+
30
+ % Iteratively perform the Gradient Vector Flow (GVF)
31
+ for i= 1 : Iterations ,
32
+ % Calculate Laplacian
33
+ Uxx= ImageDerivatives3D(u ,Sigma ,' xx' );
34
+ Uyy= ImageDerivatives3D(u ,Sigma ,' yy' );
35
+ Uzz= ImageDerivatives3D(u ,Sigma ,' zz' );
36
+
37
+ % Update the vector field
38
+ u = u + Mu *(Uxx + Uyy + Uzz ) - sMag .*(u - Fx );
39
+ clear(' Uxx' ,' Uyy' ,' Uzz' );
40
+
41
+ Vxx= ImageDerivatives3D(v ,Sigma ,' xx' );
42
+ Vyy= ImageDerivatives3D(v ,Sigma ,' yy' );
43
+ Vzz= ImageDerivatives3D(v ,Sigma ,' zz' );
44
+
45
+ v = v + Mu *(Vxx + Vyy + Vzz ) - sMag .*(v - Fy );
46
+ clear(' Vxx' ,' Vyy' ,' Vzz' );
47
+
48
+ Wxx= ImageDerivatives3D(w ,Sigma ,' xx' );
49
+ Wyy= ImageDerivatives3D(w ,Sigma ,' yy' );
50
+ Wzz= ImageDerivatives3D(w ,Sigma ,' zz' );
51
+
52
+ w = w + Mu *(Wxx + Wyy + Wzz ) - sMag .*(w - Fz );
53
+ clear(' Wxx' ,' Wyy' ,' Wzz' );
54
+ end
55
+
56
+ Fext(: ,: ,: ,1 ) = u ;
57
+ Fext(: ,: ,: ,2 ) = v ;
58
+ Fext(: ,: ,: ,3 ) = w ;
0 commit comments