图像分割基于snake模型的图像分割matlab 源码

Posted Matlab走起

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了图像分割基于snake模型的图像分割matlab 源码相关的知识,希望对你有一定的参考价值。

一、简介

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
2 原理解释
在这里插入图片描述
在这里插入图片描述

二、源代码

 
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

三、运行结果

在这里插入图片描述
在这里插入图片描述

四、备注

完整代码或者仿真咨询添加QQ1575304183

以上是关于图像分割基于snake模型的图像分割matlab 源码的主要内容,如果未能解决你的问题,请参考以下文章

图像分割之活动轮廓模型之Snake模型简介

图像分割基于matlab C-V模型水平集图像分割含Matlab源码 1456期

图像分割基于matlab C-V模型水平集图像分割含Matlab源码 1456期

图像分割基于matlab主动轮廓模型图像分割含Matlab源码 2176期

图像分割基于matlab麻雀算法优化Kmeans图像分割含Matlab源码 2030期

图像分割基于matlab麻雀算法优化Kmeans图像分割含Matlab源码 2030期