matlab水平分割函数,求助~!!急,Matlab水平集算法的图像分割程序解释

在这里:

function u = EVOLUTION(u0, g, lambda, mu, alf, epsilon, delt, numIter)

%  EVOLUTION(u0, g, lambda, mu, alf, epsilon, delt, numIter) updates the level set function

%  according to the level set evolution equation in Chunming Li et al's paper:

%      "Level Set Evolution Without Reinitialization: A New Variational Formulation"

%       in Proceedings CVPR'2005,

%  Usage:

%   u0: level set function to be updated

%   g: edge indicator function

%   lambda: coefficient of the weighted length term L(\phi)

%   mu: coefficient of the internal (penalizing) energy term P(\phi)

%   alf: coefficient of the weighted area term A(\phi), choose smaller alf

%   epsilon: the papramater in the definition of smooth Dirac function, default value 1.5

%   delt: time step of iteration, see the paper for the selection of time step and mu

%   numIter: number of iterations.

%

u=u0;

[vx,vy]=gradient(g);

for k=1:numIter

u=NeumannBoundCond(u);

[ux,uy]=gradient(u);

normDu=sqrt(ux.^2 + uy.^2 + 1e-10);

Nx=ux./normDu;

Ny=uy./normDu;

diracU=Dirac(u,epsilon);

K=curvature_central(Nx,Ny);

weightedLengthTerm=lambda*diracU.*(vx.*Nx + vy.*Ny + g.*K);

penalizingTerm=mu*(4*del2(u)-K);

weightedAreaTerm=alf.*diracU.*g;

u=u+delt*(weightedLengthTerm + weightedAreaTerm + penalizingTerm);  % update the level set function

end

% the following functions are called by the main function EVOLUTION

function f = Dirac(x, sigma)   %水平集狄拉克计算

f=(1/2/sigma)*(1+cos(pi*x/sigma));

b = (x<=sigma) & (x>=-sigma);

f = f.*b;

function K = curvature_central(nx,ny);  %曲率中心

[nxx,junk]=gradient(nx);

[junk,nyy]=gradient(ny);

K=nxx+nyy;

function g = NeumannBoundCond(f)

% Make a function satisfy Neumann boundary condition

[nrow,ncol] = size(f);

g = f;

g([1 nrow],[1 ncol]) = g([3 nrow-2],[3 ncol-2]);

g([1 nrow],2:end-1) = g([3 nrow-2],2:end-1);

g(2:end-1,[1 ncol]) = g(2:end-1,[3 ncol-2]);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值