⛳️座右铭:行百里者,半于九十。
更多Matlab图像处理仿真内容点击👇
①Matlab图像处理(进阶版)
②付费专栏Matlab图像处理(初级版)
⛳️关注CSDN海神之光,更多资源等你来!!
理论知识参考:【基础教程】基于matlab图像处理图像分割【含Matlab源码 191期】
function varargout = Segimage(varargin)
gui_Singleton = 1;
gui_State = struct(‘gui_Name’, mfilename, …
‘gui_Singleton’, gui_Singleton, …
‘gui_OpeningFcn’, @Segimage_OpeningFcn, …
‘gui_OutputFcn’, @Segimage_OutputFcn, …
‘gui_LayoutFcn’, [] , …
‘gui_Callback’, []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% — Executes just before Segimage is made visible.
function Segimage_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);
% — Outputs from this function are returned to the command line.
function varargout = Segimage_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
% -----载入图像
function inputimage_Callback(hObject, eventdata, handles)
[filename, pathname] = uigetfile( …
{‘.bmp;.jpg;.png;.tif;.jpeg’, 'Image Files (.bmp;.jpg;.png;.tif;.jpeg)’; …
‘.’, ‘All Files (.)’}, …
‘Pick an Image’);
axes(handles.axes_src);
fpath=[pathname filename];
img_src=imread(fpath);
global S
S=img_src;
imshow(img_src);
% -----绘制灰度直方图
function imhist_Callback(hObject, eventdata, handles)
global S
figure,imhist(S)
% --------------------------------------------------------------------
function Thresholdmethod_Callback(hObject, eventdata, handles)
% hObject handle to Thresholdmethod (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function Edgedet_Callback(hObject, eventdata, handles)
% hObject handle to Edgedet (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function Areamethod_Callback(hObject, eventdata, handles)
% hObject handle to Areamethod (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% ----迭代式阀值
function diedai_Callback(hObject, eventdata, handles)
axes(handles.axes_dst);
global S
tic ; %计时器
[x,y]=size(S); % 求出图象大小
b=double(S);
zd=double(max(max(S))); % 求出图象中最大的灰度
zx=double(min(min(S))) ; % 最小的灰度
T=double((zd+zx))/2; % T赋初值,为最大值和最小值的平均值
count=double(0); % 记录几次循环
while 1 % 迭代最佳阈值分割算法
count=count+1;
S0=0.0; n0=0.0; %为计算灰度大于阈值的元素的灰度总值、个数赋值
S1=0.0; n1=0.0; %为计算灰度小于阈值的元素的灰度总值、个数赋值
for i=1:x
for j=1:y
if double(S(i,j))>=T
S1=S1+double(S(i,j)); %大于阈域值图像点灰度值累加
n1=n1+1; %大于阈域值图像点个数累加
else
S0=S0+double(S(i,j)); %小于阈域值图像点灰度值累加
n0=n0+1; %小于阀域值图像点个数累加
end
end
end
T0=S0/n0; %求小于阀域值均值
T1=S1/n1; %求大于阀域值均值
if abs(T-((T0+T1)/2))<0.1 %迭代至 前后两次阀域值相差几乎为0时停止
break;
else
T=(T0+T1)/2; %在阈值T下,迭代阈值的计算过程
end
end
count ; %显示运行次数
disp(‘迭代法最佳阀值:’)
T %显示最佳阈值 算出T
toc ; %显示运算时间
i1=im2bw(S,T/255); % 图像在最佳阈值下二值化
imshow(i1);
title(‘迭代阀值分割结果’);
% -------Otsu阀值法
function otsu_Callback(hObject, eventdata, handles)
axes(handles.axes_dst);
global S
T=graythresh(S);
g=im2bw(S,T);
imshow(g);
title(‘otsu阀值分割结果’);
% ------分水岭法
function watershed_Callback(hObject, eventdata, handles)
global S
f=S;
%计算梯度图
f=double(f);
hv=fspecial(‘prewitt’);
hh=hv.';
gv=abs(imfilter(f,hv,‘replicate’));
gh=abs(imfilter(f,hh,‘replicate’));
g=sqrt(gv.2+gh.2);
%计算距离函数
df=bwdist(f);
%计算外部约束
L=watershed(df);
em=L==0;
%计算内部约束
im=imextendedmax(f,20);
%重构梯度图
g2=imimposemin(g,im|em);
%watershed算法分割
L2=watershed(g2);
axes(handles.axes_dst);
imshow(uint8(f));
title(‘分水岭法分割结果’);
% --------------------------------------------------------------------
function roberts_Callback(hObject, eventdata, handles)
% hObject handle to roberts (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
axes(handles.axes_dst);
global S
[g,t]=edge(S,‘roberts’,[],‘both’);
imshow(g);
title(‘Roberts算子分割结果’);
% --------------------------------------------------------------------
function sobel_Callback(hObject, eventdata, handles)
% hObject handle to sobel (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
axes(handles.axes_dst);
global S
[g,t]=edge(S,‘sobel’,[],‘both’);
imshow(g);
title(‘Sobel算子分割结果’);
% --------------------------------------------------------------------
function prewitt_Callback(hObject, eventdata, handles)
% hObject handle to prewitt (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
axes(handles.axes_dst);
global S
[g,t]=edge(S,‘prewitt’,[],‘both’);
imshow(g);
title(‘Prewitt算子分割结果’);
% --------------------------------------------------------------------
function log_Callback(hObject, eventdata, handles)
% hObject handle to log (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
axes(handles.axes_dst);
global S
[g,t]=edge(S,‘log’);
imshow(g);
title(‘Log算子分割结果’);
% --------------------------------------------------------------------
function canny_Callback(hObject, eventdata, handles)
% hObject handle to canny (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global S
imshow(g);
title(‘Canny算子分割结果’);
% -------区域生长法
function grow_Callback(hObject, eventdata, handles)
global S
image=S;
else
I=image;
end
1 matlab版本
2014a
2 参考文献
[1] 蔡利梅.MATLAB图像处理——理论、算法与实例分析[M].清华大学出版社,2020.
[2]杨丹,赵海滨,龙哲.MATLAB图像处理实例详解[M].清华大学出版社,2013.
[3]周品.MATLAB图像处理与图形用户界面设计[M].清华大学出版社,2013.
[4]刘成龙.精通MATLAB图像处理[M].清华大学出版社,2015.
3 备注
简介此部分摘自互联网,仅供参考,若侵权,联系删除
🍅 仿真咨询
1 各类智能优化算法改进及应用
生产调度、经济调度、装配线调度、充电优化、车间调度、发车优化、水库调度、三维装箱、物流选址、货位优化、公交排班优化、充电桩布局优化、车间布局优化、集装箱船配载优化、水泵组合优化、解医疗资源分配优化、设施布局优化、可视域基站和无人机选址优化
2 机器学习和深度学习方面
卷积神经网络(CNN)、LSTM、支持向量机(SVM)、最小二乘支持向量机(LSSVM)、极限学习机(ELM)、核极限学习机(KELM)、BP、RBF、宽度学习、DBN、RF、RBF、DELM、XGBOOST、TCN实现风电预测、光伏预测、电池寿命预测、辐射源识别、交通流预测、负荷预测、股价预测、PM2.5浓度预测、电池健康状态预测、水体光学参数反演、NLOS信号识别、地铁停车精准预测、变压器故障诊断
3 图像处理方面
图像识别、图像分割、图像检测、图像隐藏、图像配准、图像拼接、图像融合、图像增强、图像压缩感知
4 路径规划方面
旅行商问题(TSP)、车辆路径问题(VRP、MVRP、CVRP、VRPTW等)、无人机三维路径规划、无人机协同、无人机编队、机器人路径规划、栅格地图路径规划、多式联运运输问题、车辆协同无人机路径规划、天线线性阵列分布优化、车间布局优化
5 无人机应用方面
无人机路径规划、无人机控制、无人机编队、无人机协同、无人机任务分配
6 无线传感器定位及布局方面
传感器部署优化、通信协议优化、路由优化、目标定位优化、Dv-Hop定位优化、Leach协议优化、WSN覆盖优化、组播优化、RSSI定位优化
7 信号处理方面
信号识别、信号加密、信号去噪、信号增强、雷达信号处理、信号水印嵌入提取、肌电信号、脑电信号、信号配时优化
8 电力系统方面
微电网优化、无功优化、配电网重构、储能配置
9 元胞自动机方面
交通流 人群疏散 病毒扩散 晶体生长