【图像分割】基于主动轮廓模型实现图像分割附matlab代码

本文涉及的产品
视觉智能开放平台,分割抠图1万点
视觉智能开放平台,图像资源包5000点
视觉智能开放平台,视频资源包5000点
简介: 【图像分割】基于主动轮廓模型实现图像分割附matlab代码

✅作者简介:热爱科研的Matlab仿真开发者,修心和技术同步精进,matlab项目合作可私信。

🍎个人主页:Matlab科研工作室

🍊个人信条:格物致知。

更多Matlab仿真内容点击👇

智能优化算法  神经网络预测雷达通信 无线传感器

信号处理图像处理路径规划元胞自动机无人机

⛄ 内容介绍

主动轮廓模型算法是目前流行的图像分割算法, 其主要优点是无论图像的质量如何, 总可以抽取得到光滑、封闭的边界. 本文综述了主动轮廓模型算法的发展概况, 并分类介绍了各算法的特点. 此外, 本文还给出了算法发展的方向, 以及今后研究所面临的关键问题.

⛄ 部分代码

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% interate.m implements the core of the snakes (active contours) algorithm.

% It is called by the snk.m file which is the GUI frontend. If you do not

% want to deal with GUI, look at this file and the included comments which

% explain how active contours work.

%

% To run this code with GUI

%   1. Type guide on the matlab prompt.

%   2. Click on "Go to Existing GUI"

%   3. Select the snk.fig file in the same directory as this file

%   4. Click the green arrow at the top to launch the GUI

%

%   Once the GUI has been launched, you can use snakes by

%   1. Click on "New Image" and load an input image. Samples image are

%   provided.

%   2. Set the smoothing parameter "sigma" or leave it at its default value

%   and click "Filter". This will smooth the image.

%   3. As soon as you click "Filter", cross hairs would appear and using

%   them and left click of you mouse you can pick initial contour location

%   on the image. A red circle would appead everywhere you click and in

%   most cases you should click all the way around the object you want to

%   segement. The last point must be picked using a right-click in order to

%   stop matlab for asking for more points.

%   4. Set the various snake parameters (relative weights of energy terms

%   in the snake objective function) or leave them with their default value

%   and click "Iterate" button. The snake would appear and move as it

%   converges to its low energy state.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


function [smth] = interate(image, xs, ys, alpha, beta, gamma, kappa, wl, we, wt, iterations);

% image: This is the image data

% xs, ys: The initial snake coordinates

% alpha: Controls tension

% beta: Controls rigidity

% gamma: Step size

% kappa: Controls enegry term

% wl, we, wt: Weights for line, edge and terminal enegy components

% iterations: No. of iteration for which snake is to be moved



%parameters

N = iterations;

smth = image;


% Calculating size of image

[row col] = size(image);



%Computing external forces


eline = smth; %eline is simply the image intensities


[grady,gradx] = gradient(smth);

eedge = -1 * sqrt ((gradx .* gradx + grady .* grady)); %eedge is measured by gradient in the image


%masks for taking various derivatives

m1 = [-1 1];

m2 = [-1;1];

m3 = [1 -2 1];

m4 = [1;-2;1];

m5 = [1 -1;-1 1];


cx = conv2(smth,m1,'same');

cy = conv2(smth,m2,'same');

cxx = conv2(smth,m3,'same');

cyy = conv2(smth,m4,'same');

cxy = conv2(smth,m5,'same');


for i = 1:row

   for j= 1:col

       % eterm as deined in Kass et al Snakes paper

       eterm(i,j) = (cyy(i,j)*cx(i,j)*cx(i,j) -2 *cxy(i,j)*cx(i,j)*cy(i,j) + cxx(i,j)*cy(i,j)*cy(i,j))/((1+cx(i,j)*cx(i,j) + cy(i,j)*cy(i,j))^1.5);

   end

end


% imview(eterm);

% imview(abs(eedge));

eext = (wl*eline + we*eedge -wt * eterm); %eext as a weighted sum of eline, eedge and eterm


[fx, fy] = gradient(eext); %computing the gradient



%initializing the snake

xs=xs';

ys=ys';

[m n] = size(xs);

[mm nn] = size(fx);

   

%populating the penta diagonal matrix

A = zeros(m,m);

b = [(2*alpha + 6 *beta) -(alpha + 4*beta) beta];

brow = zeros(1,m);

brow(1,1:3) = brow(1,1:3) + b;

brow(1,m-1:m) = brow(1,m-1:m) + [beta -(alpha + 4*beta)]; % populating a template row

for i=1:m

   A(i,:) = brow;

   brow = circshift(brow',1)'; % Template row being rotated to egenrate different rows in pentadiagonal matrix

end


[L U] = lu(A + gamma .* eye(m,m));

Ainv = inv(U) * inv(L); % Computing Ainv using LU factorization

 

%moving the snake in each iteration

for i=1:N;

   

   ssx = gamma*xs - kappa*interp2(fx,xs,ys);

   ssy = gamma*ys - kappa*interp2(fy,xs,ys);

   

   %calculating the new position of snake

   xs = Ainv * ssx;

   ys = Ainv * ssy;

   

   

   %Displaying the snake in its new position

   imshow(image,[]);

   hold on;

   

   plot([xs; xs(1)], [ys; ys(1)], 'r-');

   hold off;

   pause(0.001)    

end;


⛄ 运行结果

⛄ 参考文献

[1]吴北海. 基于主动轮廓模型的医学图像分割[D]. 河北工业大学.

[2]高梅, and 余轮. "基于主动轮廓模型的图像分割算法." 漳州师范学院学报(自然科学版) (2007).

❤️ 关注我领取海量matlab电子书和数学建模资料
❤️部分理论引用网络文献,若有侵权联系博主删除


相关文章
|
4月前
|
安全
【2023高教社杯】D题 圈养湖羊的空间利用率 问题分析、数学模型及MATLAB代码
本文介绍了2023年高教社杯数学建模竞赛D题的圈养湖羊空间利用率问题,包括问题分析、数学模型建立和MATLAB代码实现,旨在优化养殖场的生产计划和空间利用效率。
215 6
【2023高教社杯】D题 圈养湖羊的空间利用率 问题分析、数学模型及MATLAB代码
|
4月前
|
存储 算法 搜索推荐
【2022年华为杯数学建模】B题 方形件组批优化问题 方案及MATLAB代码实现
本文提供了2022年华为杯数学建模竞赛B题的详细方案和MATLAB代码实现,包括方形件组批优化问题和排样优化问题,以及相关数学模型的建立和求解方法。
139 3
【2022年华为杯数学建模】B题 方形件组批优化问题 方案及MATLAB代码实现
|
4月前
|
数据采集 存储 移动开发
【2023五一杯数学建模】 B题 快递需求分析问题 建模方案及MATLAB实现代码
本文介绍了2023年五一杯数学建模竞赛B题的解题方法,详细阐述了如何通过数学建模和MATLAB编程来分析快递需求、预测运输数量、优化运输成本,并估计固定和非固定需求,提供了完整的建模方案和代码实现。
105 0
【2023五一杯数学建模】 B题 快递需求分析问题 建模方案及MATLAB实现代码
|
7月前
|
数据安全/隐私保护
耐震时程曲线,matlab代码,自定义反应谱与地震波,优化源代码,地震波耐震时程曲线
地震波格式转换、时程转换、峰值调整、规范反应谱、计算反应谱、计算持时、生成人工波、时频域转换、数据滤波、基线校正、Arias截波、傅里叶变换、耐震时程曲线、脉冲波合成与提取、三联反应谱、地震动参数、延性反应谱、地震波缩尺、功率谱密度
基于混合整数规划的微网储能电池容量规划(matlab代码)
基于混合整数规划的微网储能电池容量规划(matlab代码)
|
7月前
|
算法 调度
含多微网租赁共享储能的配电网博弈优化调度(含matlab代码)
含多微网租赁共享储能的配电网博弈优化调度(含matlab代码)
|
7月前
|
Serverless
基于Logistic函数的负荷需求响应(matlab代码)
基于Logistic函数的负荷需求响应(matlab代码)
|
7月前
|
数据安全/隐私保护
地震波功率谱密度函数、功率谱密度曲线,反应谱转功率谱,matlab代码
地震波格式转换、时程转换、峰值调整、规范反应谱、计算反应谱、计算持时、生成人工波、时频域转换、数据滤波、基线校正、Arias截波、傅里叶变换、耐震时程曲线、脉冲波合成与提取、三联反应谱、地震动参数、延性反应谱、地震波缩尺、功率谱密度
|
7月前
|
算法 调度
面向配电网韧性提升的移动储能预布局与动态调度策略(matlab代码)
面向配电网韧性提升的移动储能预布局与动态调度策略(matlab代码)
|
7月前
|
运维 算法
基于改进遗传算法的配电网故障定位(matlab代码)
基于改进遗传算法的配电网故障定位(matlab代码)

热门文章

最新文章