% This Matlab file demomstrates a narrow band algorithm that 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.
% Author: Chunming Li, all rights reserved.
% E-mail: li_chunming@hotmail.com
% URL: http://222.178.203.72:19005/whst/63/_vvvzdmfqztbnmmzdct//~cmli/
clear all;
close all;
Img = imread('twoObjImg.bmp');
Img=double(Img(:,:,1));
sigma=1.5; % scale parameter in Gaussian kernel for smoothing.
[nrow, ncol]=size(Img);
total_time = 0;
G=fspecial('gaussian',15,sigma);
Img_smooth=conv2(Img,G,'same'); % smooth image by Gaussiin convolution
[Ix,Iy]=gradient(Img_smooth);
f=Ix.^2+Iy.^2;
g=1./(1+f); % edge indicator function.
[vx,vy] = gradient(g);
tic;
total_time = total_time + toc;
epsilon=1.5; % the papramater in the definition of smoothed Dirac function
N_iter=150;
timestep=5; % time step
mu=0.04; % coefficient of the internal (penalizing) energy term P(\phi)
% Note: The product timestep*mu must be less than 0.25 for stable evolution
DiracSigma=1.5; % the papramater in the definition of smoothed Dirac function
lambda=5; % coefficient of the weighted length term Lg(\phi)
alf=3; % coefficient of the weighted area term Ag(\phi);
% Note: Choose a positive(negative) alf if the initial contour is outside(inside) the object.
d = 1; % specify the width of the narrow band. The narrow band is
% the union of (2d+1)x(2d+1) blocks centered at the zero crossing pixels.
% Note: don't change this parameter for this version (nband_v14).
epsilon = .000001; % small positive number added to the denominator to avoid 0 in the denominator
rad = d;
vs=d+1;
figure;imagesc(Img, [0, 255]);colormap(gray);hold on;
text(6,6,'Left click to get points, right click to get end point','FontSize',[12],'Color', 'r');
% Use mouse to obtain initial contour/region;
BW = roipoly; % get a region R inside a polygon, BW is a binary image with 1 and 0 inside or outside the polygon;
c0=2; % The constant value used to define binary level set function as initial LSF;
% Using larger value of c0 usually slows down the evolution.
initialLSF= c0*2*(0.5-BW); % initial level set function: -c0 inside R, c0 outside R;
u=initialLSF;
figure;imagesc(Img, [0, 255]);colormap(gray);hold on;
[c,h] = contour(u,[0 0],'b');
title('Initial contour');
%initial bandmap,
bandMap = initializeNB(u);
total_iter_time = 0;
ops{1}.name = 'normalGradient';
ops{end+1}.name = 'Dirac';
ops{end+1}.name = 'curvature';
ops{end+1}.name = 'computeDataTerm';
ops{end+1}.name = 'updateLSF';
ops{end+1}.name = 'updateZeroCrossBand';
ops{end+1}.name = 'updateZCBand init';
ops{end+1}.name = 'total time';
total_stats = zeros(length(ops), 1);
tic;
t1=cputime;
[u, bandMap, ux, uy, Nx, Ny, diracU, K, ABD, f, E,Stats] = ...
nband_v14(u, bandMap, DiracSigma, vs, lambda, alf, mu, timestep, rad, vx, vy, g, nrow, ncol, N_iter);
t2=cputime;
iterationTime=t2-t1
total_stats = total_stats + Stats;
total_iter_time = total_iter_time + toc;
total_time = total_time + total_iter_time;
%hold on;
figure;imagesc(Img, [0, 255]);colormap(gray);hold on;
[c,h] = contour(u,[0 0],'r');
iterNum=[num2str(N_iter), ' iterations'];
title(iterNum);
disp(' ');
printStats(ops, total_stats);
disp(' ');
% display statistics of CPU times
disp(' =============== time statistics (Matlab) ================');
disp(sprintf('%26s\t %.6g s', 'total iteration time', total_iter_time));
disp(sprintf('%26s\t %.6g s', 'total time (init/iter)', total_time));
disp(' ');
weixin_42653672
- 粉丝: 111
- 资源: 1万+
最新资源
- 使用群晖NAS搭建虚拟机
- 基于minifly的学习源码-本人耗时五年完善的稳定源码移植于minifly上,不带操作系统,直接操作寄存器,代码简洁明了,算法基于数学公式,便于学习数学知识
- 基于motorcad设计的外转子发电机,磁钢采用FB6B铁氧体 ,不等匝绕组,输出功率2.3KW 定子外径156 3200RPM,18极27槽永磁同步发电机(PMSG)设计案例.
- 电力电子、电机驱动、数字滤波器matlab simulink仿真模型实现及相关算法的C代码实现 配置C2000 DSP ADC DAC PWM定时器 中断等模块,提供simulink与DSP的联合仿
- 视觉系统程序,新能源电池检测 1、支持4个相机 2、实现Profinet网卡通信 3、实现日志功能 4、实现图像存储功能 5、实现电芯有无判断、电芯和端板涂胶检测
- 基于51单片机的电子时钟设计
- 西门子smart200与汇川变频器 Modbus RTU控制程序 步科触摸屏程序 振捣控制系统 汇川变频器手册
- C#上位机与西门子plc通信,实现伺服控制与数字量控制 提供C#源代码,plc测试程序
- 45.<资源>番茄钟3.0 无代码 C#例子 WPF例子
- stm32f103的Bootloader IAP串口升级stm32f103的Bootloader IAP串口升级st m32固件的学习资料,成熟产品方案已经用在批量产品上,资料包括上位机(电脑端)运行
- 基于Spark的电商用户行为分析系统-源码+课设论文(本科期末课程设计).zip
- Qt C++pdf阅读器源码 上下翻页 精美工具栏 支持ofd格式 1. 仿WPS界面 2. 预览PDF文件 3. 支持PDF预览放大,缩小 4. 支持目录预览查看 5. 支持目录点击跳转页查
- RDM(radis桌面工具)
- 西门子s7 200smart与3台台达VFD-M变频器通讯目标:用触摸屏和西门子smart 控制3台台达变频器通讯 器件:西门子s7 200 smart PLC,3台台达VFD-M变频器,昆仑通态触摸
- 基于51单片机的电子密码锁设计
- Qt5工业上位机源码 工业电子称 无线扫码器 串口的使用 Qt5.14可运行 Qt5工业上位机应用! 一套完整工程! 工业电子称使用, 无线扫码枪的使用, 串口的使用 使用Qt5.14 用QtCrea
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈