function [phi,c1,c2] = ActiveContours_const(u0, nu,lambda1,lambda2,TimeSteps) % EXAMPLE: % u0 is the gray scale image % This program is written by Chiu-Yen Kao % Reference: T.F. Chan and L.A. Vese, Active Contours without edges, IEEE % transactions on Image Processing, 2001, 10(2): 266-277. [M,N] = size(u0); % possibly Color picture % plot figure every plot_iter plot_iter = 20; max_iter_phi = 1; % create an initial guess for phi x = 1:M; y = 1:N; dx = 1; dy = 1; dt = (10e7) * 0.9 / ((2*nu/(dx^2)) + (2*nu/(dy^2))); [X,Y] = meshgrid(x,y); x0 = (M+1)/2; y0 = (N+1)/2; r0 = (min(M,N))/3; phi = sqrt((X-x0).^2 + (Y-y0).^2) - r0; phi = phi'; for(n=1:TimeSteps) disp(['The number of iteration is ' num2str(n)]) if mod(n-1,plot_iter) ==0 figure(1);clf imagesc(u0, [0 255]); colormap(gray); axis image; hold on axis image; contour(Y,X,phi',[0 0],'m');drawnow figure(2) mesh(Y,X,phi') end c1 = C1(u0,phi); c2 = C2(u0,phi); % Gauss-Jacobi iteration iter = 0; error_phi = 1; while (error_phi > 1.e-1) & (iter 0) numerator = numerator + u0(i,j); denominator = denominator + 1; end end end denominator = denominator; value = numerator / denominator; function value = DiracDelta(x,epsilon) % DIRAC Dirac function of x % DIRAC( x, epsilon ) Computes the derivative of the heaviside % function of x with respect to x. Regularized based on epsilon. value = ( 1 ./ pi ) .* ( epsilon ./ ( epsilon.^2 + x.^2 ) );