www.pudn.com > MATLAB.zip > PLSE_demo3.m, change:2006-08-04,size:2029b

%  **********   Do not distribute this file  ***********
% This Matlab program implements the level set method in Li et al's paper
%    "Level Set Evolution Without Re-initialization: A New Variational Formulation"
%    in Proceedings of CVPR'05, vol. 1, pp. 430-436.
% Copyright (c) 2004--2007 by Chunming Li
% Author: Chunming Li
% Revision by Chunming Li 4/25/2006
% e-mail: li_chunming@hotmail.com
% http://vuiis.vanderbilt.edu/~licm/

clear all;
close all;
% Img = imread('twocells.bmp');  % The same cell image in the paper is used

[X,Y,Img]=peaks(100);

[Ix,Iy]=gradient(Img);
imshow(uint8(Img));
figure;
f=Ix.^2+Iy.^2;
% g = max(max(f))-f;
g=1./(1+f);  % edge indicator function.
imshow(g);

lambda=5; % coefficient of the weighted length term L(\phi)
mu=0.04;  % coefficient of the internal (penalizing) energy term P(\phi)
alf=1.5;  % coefficient of the weighted area term A(\phi)
epsilon=0.5; % the papramater in the definition of smooth Dirac function
timestep=2;  % time step

% define initial level set function (LSF) as -c, 0, c at points outside, on
% the boundary, and inside of a region R, respectively.
[nrow, ncol]=size(Img);
c=3;
initialLSF=c*ones(nrow,ncol);
d=8;
initialLSF(d+1:end-d, d+1:end-d)=0;  % zero level set on the boundary of R
initialLSF(d+2:end-d-1, d+2: end-d-1)=-c; % negative constant inside of R
u=initialLSF;
figure;imagesc(Img);colormap(gray);hold on;
[c,h] = contour(u,[0 0],'g');

title('Initial contour');
% start level set evolution
for n=1:500
u=EVOLUTION_PLSE(u, g ,lambda, mu, alf, epsilon, timestep, 1);
pause(0.05);
if mod(n,20)==0
imagesc(Img);colormap(gray);hold on;
[c,h] = contour(u,[0 0],'r');
iterNum=[num2str(n), ' iterations'];
title(iterNum);
hold off;
end
end
imagesc(Img);colormap(gray);hold on;
[c,h] = contour(u,[0 0],'r');
totalIterNum=[num2str(n), ' iterations'];
title(['Final contour, ', totalIterNum]);