【图像分割】基于matlab Snake模型图像分割【含Matlab源码 418期】
【摘要】
一、获取代码方式
获取代码方式1: 通过订阅紫极神光博客付费专栏,凭支付凭证,私信博主,可获得此代码。
获取代码方式2: 完整代码已上传我的资源:【图像分割】基于matlab Snake模型图像分割【...
一、获取代码方式
获取代码方式1:
通过订阅紫极神光博客付费专栏,凭支付凭证,私信博主,可获得此代码。
获取代码方式2:
完整代码已上传我的资源:【图像分割】基于matlab Snake模型图像分割【含Matlab源码 418期】
备注:
订阅紫极神光博客付费专栏,可免费获得1份代码(有效期为订阅日起,三天内有效);
二、图像分割简介
理论知识参考:【基础教程】基于matlab图像处理图像分割【含Matlab源码 191期】
三、部分源代码
clear all;
close all;
Img = imread('twocells.bmp'); % The same cell image in the paper is used here
Img=double(Img(:,:,1));
sigma=1.5; % scale parameter in Gaussian kernel for smoothing.
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.
epsilon=1.5; % the papramater in the definition of smoothed Dirac function
timestep=5; % time step
mu=0.2/timestep; % coefficient of the internal (penalizing) energy term P(\phi)
% Note: the product timestep*mu must be less than 0.25 for stability!
lambda=5; % coefficient of the weighted length term L(\phi)
alf=1.5; % coefficient of the weighted area term A(\phi);
% Note: Choose smaller value for weak object bounday, such as the cell image in this demo.
% 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);
c0=4;
initialLSF=c0*ones(nrow,ncol);
w=8;
initialLSF(w+1:end-w, w+1:end-w)=0; % zero level set is on the boundary of R.
% Note: this can be commented out. The intial LSF does NOT necessarily need a zero level set.
initialLSF(w+2:end-w-1, w+2: end-w-1)=-c0; % negative constant -c inside of R, postive constant c outside 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:300
u=EVOLUTION(u, g ,lambda, mu, alf, epsilon, timestep, 1);
pause(0.001);
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
% 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=4;
initialLSF=c*ones(nrow,ncol);
w=10;
initialLSF(w+1:end-w, w+1:end-w)=0; % zero level set is on the boundary of R.
% Note: this can be commented out. The intial LSF does NOT necessarily need a zero level set.
initialLSF(w+2:end-w-1, w+2: end-w-1)=-c; % negative constant -c inside of R, postive constant c outside of R.
u=initialLSF;
figure;imagesc(Img, [0, 255]);colormap(gray);hold on;
[c,h] = contour(u,[0 0],'r');
title('Initial contour');
% start level set evolution
for n=1:500
u=EVOLUTION(u, g ,lambda, mu, alf, epsilon, timestep, 1);
pause(0.001);
if mod(n,20)==0
imagesc(Img, [0, 255]);colormap(gray);hold on;
[c,h] = contour(u,[0 0],'r');
iterNum=[num2str(n), ' iterations'];
title(iterNum);
hold off;
end
end
四、运行结果
五、matlab版本及参考文献
1 matlab版本
2014a
2 参考文献
[1] 蔡利梅.MATLAB图像处理——理论、算法与实例分析[M].清华大学出版社,2020.
[2]杨丹,赵海滨,龙哲.MATLAB图像处理实例详解[M].清华大学出版社,2013.
[3]周品.MATLAB图像处理与图形用户界面设计[M].清华大学出版社,2013.
[4]刘成龙.精通MATLAB图像处理[M].清华大学出版社,2015.
[5]赵勇,方宗德,庞辉,王侃伟.基于量子粒子群优化算法的最小交叉熵多阈值图像分割[J].计算机应用研究. 2008,(04)
文章来源: qq912100926.blog.csdn.net,作者:海神之光,版权归原作者所有,如需转载,请联系作者。
原文链接:qq912100926.blog.csdn.net/article/details/114221660
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)