% This Matlab program demomstrates the level set algorithm in paper:
% "Active contours with selective local or global segmentation: a new variational approach and level set method"
% to appear in Image and Vision Computing, 2010.
% Authors: Kaihua Zhang, Lei Zhang, Huihui Song and Wengang Zhou
% E-mail: zhkhua@mail.ustc.edu.cn, cslzhang@comp.polyu.edu.hk
% URL: http://www4.comp.polyu.edu.hk/~cslzhang/
% Notes:Some parameters may need to be modified for different types of images.
% Please contact the authors if any problem regarding the choice of parameters.
% Date: 5/11/2009
clc;clear all;close all;
Img = imread('11.jpg');
Img = Img(:,:,1);
Img = double(Img);
% Img = 200*ones(100);
% Img(20:80,10:30)= 140;
% Img(20:80,40:70)= 180;
% Img(20:80,80:90)=50;
[row,col] = size(Img);
phi = ones(row,col);
phi(110:row-150,155:col-200) = -1;
u = - phi;
[c, h] = contour(u, [0 0], 'r');
title('Initial contour');
% hold off;
sigma = 0.004;
G = fspecial('gaussian', 5, sigma);
delt = 0.2;
Iter = 400;
mu = 18;%this parameter needs to be tuned according to the images
for n = 1:Iter
[ux, uy] = gradient(u);
c1 = sum(sum(Img.*(u<0)))/(sum(sum(u<0)));% we use the standard Heaviside function which yields similar results to regularized one.
c2 = sum(sum(Img.*(u>=0)))/(sum(sum(u>=0)));
spf = Img - (c1 + c2)/2;
spf = spf/(max(abs(spf(:))));
u = u + delt*(mu*spf.*sqrt(ux.^2 + uy.^2));
if mod(n,10)==0
imagesc(Img,[0 255]); colormap(gray);hold on;
[c, h] = contour(u/2, [0 0], 'r');
iterNum = [num2str(n), 'iterations'];
title(iterNum);
pause(0.02);
end
u = (u >= 0) - ( u< 0);% the selective step.
u = conv2(u, G, 'same');
end
imagesc(Img,[0 255]);colormap(gray);hold on;
[c, h] = contour(u, [0 0], 'b');
seg.zip_seg_segmentation_zip
版权申诉
114 浏览量
2022-09-23
01:16:13
上传
评论
收藏 2KB ZIP 举报
局外狗
- 粉丝: 69
- 资源: 1万+
最新资源
- 类和对象知识点练习及其参考答案
- C++职工管理系统:本教程主要利用C++来实现一个基于多态的职工管理系统
- 基于原生微信小程序实现的课堂考勤系统的设计与实现
- 商道融绿、润灵环球ESG评级数据(2015-2023年).xlsx
- 商道融绿、润灵环球ESG评级数据(2015-2023年).dta
- 基于 GDAL 与 PROJ4 的遥感图像处理软件,使用 Qt 构建课程设计
- 图形化界面采用Easyx编写,实现对哈夫曼树的显示操作
- 使用后端开发框架Spring Boot构建应用程序.pdf
- 基于Boson的计算机网络实验:RIP和IGRP的配置
- 在线教育系统 JAVA+Vue+SpringBoot+MySQL
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈