-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathGVFOptimizeImageForces2D.m
44 lines (37 loc) · 1.23 KB
/
GVFOptimizeImageForces2D.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
function Fext=GVFOptimizeImageForces2D(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 = GVFOptimizeImageForces2D(Fext, Mu, Iterations, Sigma)
%
% inputs,
% Fext : The image force vector field N x M x 2
% 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);
% Calculate magnitude
sMag = Fx.^2+ Fy.^2;
% Set new vector-field to initial field
u=Fx; v=Fy;
% Iteratively perform the Gradient Vector Flow (GVF)
for i=1:Iterations,
% Calculate Laplacian
Uxx=ImageDerivatives2D(u,Sigma,'xx');
Uyy=ImageDerivatives2D(u,Sigma,'yy');
Vxx=ImageDerivatives2D(v,Sigma,'xx');
Vyy=ImageDerivatives2D(v,Sigma,'yy');
% Update the vector field
u = u + Mu*(Uxx+Uyy) - sMag.*(u-Fx);
v = v + Mu*(Vxx+Vyy) - sMag.*(v-Fy);
end
Fext(:,:,1) = u;
Fext(:,:,2) = v;