www.pudn.com > MATLAB.zip > PLSE_demo2.m, change:2015-01-15,size:2187b

%  **********   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('twoObj.bmp');  % The same cell image in the paper is used here
Img=double(Img(:,:,1));
sigma=1.2;    % scale parameter in Gaussian kernel
G=fspecial('gaussian',15,sigma);
Img_smooth=conv2(Img,G,'same');  % smooth image by Gaussiin convolution
f=Ix.^2+Iy.^2;
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=3;  % coefficient of the weighted area term A(\phi)
epsilon=1.5; % the papramater in the definition of smooth Dirac function
timestep=5;  % 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 is 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],'r');

title('Initial contour');
% start level set evolution
for n=1:200
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]);