-
Notifications
You must be signed in to change notification settings - Fork 3
/
SnakeMoveIteration2D.m
72 lines (64 loc) · 1.87 KB
/
SnakeMoveIteration2D.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
function P = SnakeMoveIteration2D(B, P, Fext0, gamma, kappa, delta, ForceOnCurve, varargin)
% This function will calculate one iteration of contour Snake movement
%
% P=SnakeMoveIteration2D(S,P,Fext,gamma,kappa)
%
% inputs,
% B : Internal force (smoothness) matrix
% P : The contour points N x 2;
% Fext : External vector field (from image)
% gamma : Time step
% kappa : External (image) field weight
% delta : Balloon Force weight
%
% outputs,
% P : The (moved) contour points N x 2;
%
% Function is written by D.Kroon University of Twente (July 2010)
% Clamp contour to boundary
P(:,1)=min(max(P(:,1),1),size(Fext0,1));
P(:,2)=min(max(P(:,2),1),size(Fext0,2));
% Get image force on the contour points
if ForceOnCurve
% open ends only for now
Fext1 = kappa * curvewise_edge_energy( Fext0, P);
else
Fext1 = kappa * pointwise_edge_energy( Fext0, P);
end
Closed = false;
% if Closed
% Calculate the baloonforce on the contour points
N = GetContourNormals2D(P, Closed);
Fext2 = delta*N; %
% Fext2 = zeros(size(N));%
% else
% Fext2 = zeros(size(Fext1));%
% end
% Update contour positions
ssx = P(:,1) + ( Fext1(:,1) + Fext2(:,1)) / gamma;
ssy = P(:,2) + ( Fext1(:,2) + Fext2(:,2) ) / gamma;
if ~isempty(varargin) && ~isempty(varargin{1})
fixed = varargin{1};
if size(fixed,2) == 1
P_fix = [P(fixed,1), P(fixed,1)];
elseif size(fixed,2) == 2
P_fix = P(fixed);
else
error('wrong array of fixed points')
end
end
P(:,1) = gamma* B * ssx;
P(:,2) = gamma* B * ssy;
if ~isempty(varargin) && ~isempty(varargin{1})
if size(fixed,2) == 1
P(fixed, 1) = P_fix(:,1);
P(fixed, 2) = P_fix(:,2);
elseif size(fixed,2) == 2
P(fixed) = P_fix;
else
error('wrong array of fixed points')
end
end
% Clamp contour to boundary
P(:,1)=min(max(P(:,1),1),size(Fext0,1));
P(:,2)=min(max(P(:,2),1),size(Fext0,2));