1 function Fext=GVFOptimizeImageForces2D(Fext, Mu, Iterations, Sigma)
\r
2 % This function "GVFOptimizeImageForces" does gradient vector flow (GVF)
\r
3 % on a vector field. GVF gives the edge-forces a larger capature range,
\r
4 % to make the snake also reach concave regions
\r
6 % Fext = GVFOptimizeImageForces2D(Fext, Mu, Iterations, Sigma)
\r
9 % Fext : The image force vector field N x M x 2
\r
10 % Mu : Is a trade of scalar between noise and real edge forces
\r
11 % Iterations : The number of GVF itterations
\r
12 % Sigma : Used when calculating the Laplacian
\r
15 % Fext : The GVF optimized image force vector field
\r
17 % Function is written by D.Kroon University of Twente (July 2010)
\r
19 % Squared magnitude of force field
\r
23 % Calculate magnitude
\r
24 sMag = Fx.^2+ Fy.^2;
\r
26 % Set new vector-field to initial field
\r
29 % Iteratively perform the Gradient Vector Flow (GVF)
\r
31 % Calculate Laplacian
\r
32 Uxx=ImageDerivatives2D(u,Sigma,'xx');
\r
33 Uyy=ImageDerivatives2D(u,Sigma,'yy');
\r
35 Vxx=ImageDerivatives2D(v,Sigma,'xx');
\r
36 Vyy=ImageDerivatives2D(v,Sigma,'yy');
\r
38 % Update the vector field
\r
39 u = u + Mu*(Uxx+Uyy) - sMag.*(u-Fx);
\r
40 v = v + Mu*(Vxx+Vyy) - sMag.*(v-Fy);
\r