1. 参考文献
2. LCV模型
%demo_LCV.m
%Author: HSW
%Date;2015/4/12
%HARBIN INSTITUTE OF TECHNOLOGY
% Set Matlab
close all;
clear all;
clc;
% demo 编号,需要修改
ii = 1;
% Add path
addpath(genpath('Image\'));
addpath(genpath('LCV solver\'));
% save result path
SaveFilePath = 'Results\';
% Read Image
c0 = 2;
imgID = 6;
Img = imread('Image\vessel2.bmp');
Temp = Img;
if ndims(Img) == 3
Img = rgb2gray(Img);
end
Img = double(Img);
% Initial phi is the level set function
switch imgID
case 1
phi= ones(size(Img(:,:,1))).*c0;
a=43;b=51;c=20;d=28;
phi(a:b,c:d) = -c0;
figure;
imshow(Temp);colormap;
hold on;
[c,h] = contour(phi, 0, 'r');
hold off;
case 2
[m,n] = size(Img(:,:,1));
a=m/2; b=n/2; r=min(m,n)/4;%set the radius
phi= ones(m,n).*c0;
phi(a-r:a+r,b-r:b+r) = -c0;
imshow(Temp);colormap;
hold on;
[c,h] = contour(phi, 0, 'r');
hold off;
case 3
figure;
imshow(Temp);colormap;
text(6,6,'Left click to get points, right click to get end point','FontSize',12,'Color', 'g');
BW=roipoly; %BW is mask
phi=c0*2*(0.5-BW);
hold on;
[c,h] = contour(phi,[0 0],'r');
hold off;
case 4
%figure;imagesc(Img,[0,255]);colormap(gray);hold on; axis off; axis equal;
figure;
imshow(Temp);colormap;
[x,y] = ginput(9);%set nine centre points of nine initial level set function
[m,n] = size(Img);
r = min(m,n)/6; %we need to set the radius
phi= ones(m,n).*c0;
for iter = 1:length(x)
phi(x(iter)-r:x(iter)+r,y(iter)-r:y(iter)+r) = -c0;%initial zero level set is square
% initial zero level set is circle,this method is not recommended
% for i = 1:m
% for j = 1:n
% d = (i - x(iter))^2 + (j - y(iter))^2;
% if d <= r^2
% phi(i,j) = -c0;
% end%if
% end% j
% end% i
% 上述注释部分为实现选择的中心点初始化为圆形,不推荐这种方法
end% iter
hold on;
[c,h] = contour(phi,[0 0],'r');
hold off;
case 5
%figure;imagesc(Img,[0,255]);colormap(gray);hold on; axis off; axis equal;
figure;
imshow(Temp);colormap;