cvCopyImage、memcpy等函数将现在的图像复制一个,采用复制的图像进行处理即可啊。
如果是存在处理当前图像,还希望保存前一个图像,则可以定义一个图像变量,本次结束前将图像复制到指定的图像变量内,也可以采用cvSaveImage函数将图像保存到硬盘,等下次需要再出来。
u=EVOLUTION(u, g ,lambda, mu, alf, epsilon, timestep, 1)必须要有函数支持,或者调用动态链接库(dll)。
核心代码在这个函数或dll文件中。
在这里: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])
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)