💥💥💥💥💥💥💞💞💞💞💞💞💞💞欢迎来到海神之光博客之家💞💞💞💞💞💞💞💞💥💥💥💥💥💥
✅博主简介:热爱科研的Matlab仿真开发者,修心和技术同步精进;
🍎个人主页:海神之光
🏆代码获取方式:
海神之光Matlab王者学习之路—代码获取方式
⛳️座右铭:行百里者,半于九十。
更多Matlab图像处理仿真内容点击👇
①Matlab图像处理(进阶版)
②付费专栏Matlab图像处理(初级版)
⛳️关注优快云海神之光,更多资源等你来!!
⛄一、均值漂移简介
1.均值漂移的基本概念:沿着密度上升方向寻找聚簇点
(1)设想在一个有N个样本点的特征空间;
(2)初始确定一个中心点center,计算在设置的半径为D的圆形空间内所有的点(xi)与中心点center的向量;
(3)计算整个圆形空间内所有向量的平均值,得到一个偏移均值;
(4)将中心点center移动到偏移均值位置;
(5)重复移动,直到满足一定条件结束;
2 均值漂移运算:
2.1 Mean shift的基础公式:
偏移均值
Sh:以x为中心点,半径为h的高维球区域; k:包含在Sh范围内点的个数; xi:包含在Sh范围内的点
中心更新
将中心点移动到偏移均值位置
Mt为t状态下求得的偏移均值; xt为t状态下的中心
2.2 引入核函数的偏移均值:
核函数
核函数只是用来计算映射到高维空间之后的内积的一种简便方法,目的为让低维的不可分数据变成高维可分。利用核函数,可以忽略映射关系,直接在低维空间中完成计算。
引入核函数的偏移均值
在均值漂移中引入核函数的概念,能够使计算中距离中心的点具有更大的权值,反映距离越短,权值越大的特性。改进的偏移均值:
其中,x为中心点;xi为带宽范围内的点;n为带宽范围内的点的数量;g(x)为对核函数的导数求负
3 均值漂移的应用:
聚类(K均值聚类)
图像分割(将图像映射到特征空间,对采样点进行均值漂移聚类)
对象轮廓检验(光线传播算法)
目标跟踪(求解最优化Bhattacharya系数函数)
4 均值漂移运算步骤:
4.1 在未被分类的数据点中随机选择一个点作为中心点;
4.2 找出离中心点距离在带宽之内的所有点,记做集合M,认为这些点属于簇c。
4.3 计算从中心点开始到集合M中每个元素的向量,将这些向量相加,得到偏移向量。
4.4 中心点沿着shift的方向移动,移动距离是偏移向量的模。
4.5 重复步骤2、3、4,直到偏移向量的大小满足设定的阈值要求,记住此时的中心点。
4.6 重复1、2、3、4、5直到所有的点都被归类。
4.7 分类:根据每个类,对每个点的访问频率,取访问频率最大的那个类,作为当前点集的所属类。
⛄二、部分源代码
function varargout = GUI(varargin)
gui_Singleton = 1;
gui_State = struct(‘gui_Name’, mfilename, …
‘gui_Singleton’, gui_Singleton, …
‘gui_OpeningFcn’, @GUI_OpeningFcn, …
‘gui_OutputFcn’, @GUI_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
function GUI_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
handles.FileName = 0;
colour = get(handles.Video_Panel,‘BackgroundColor’);
img = imread(‘Files\Play_up.bmp’);
handles.icon_play_up = Set_Button_Bckgrnd(img,colour);
set(handles.Play,‘CData’,handles.icon_play_up);
img = imread(‘Files\Play_down.bmp’);
handles.icon_play_down = Set_Button_Bckgrnd(img,colour);
set(handles.Speed,‘Value’,10);
in = imread(‘Files\Mark_in.bmp’);
out = imread(‘Files\Mark_out.bmp’);
in = Set_Button_Bckgrnd(in,colour);
out = Set_Button_Bckgrnd(out,colour);
set(handles.Mark_in,‘CData’,in);
set(handles.Mark_out,‘CData’,out);
icon = imread(‘Files\Crop.bmp’);
icon = Set_Button_Bckgrnd(icon,colour);
set(handles.Crop,‘CData’,icon);
icon = imread(‘Files\Select_Target.bmp’);
icon = Set_Button_Bckgrnd(icon,colour);
set(handles.Select_Target,‘CData’,icon);
set(handles.Gaussian,‘Value’,1);
handles.Kernel_type = ‘Gaussian’;
handles.radius = str2double(get(…
handles.Radius_edit,‘String’))/100;
% Set Default Iteration limiters
handles.f_thresh = str2double(get(…
handles.F_thresh_edit,‘String’));
handles.max_iter = str2double(get(…
handles.Max_iter_edit,‘String’));
% Update handles structure
guidata(hObject, handles);
%Display Default Images
axes(handles.Target)
img = imread(‘Files\Target_Default.png’);
imshow(img);
axes(handles.Video)
img = imread(‘Files\Video_Default.png’);
imshow(img);
%% Button Background Colour Function
function icon = Set_Button_Bckgrnd(icon,colour)
for i=1:size(icon,1)
for j=1:size(icon,2)
if mean(icon(i,j,:))>= 196
icon(i,j,:) = icon(i,j,:)-uint8(round(…
255*(ones(1,1,3)-permute(colour,[1 3 2]))));
end
end
end
%% Outputs from this function are returned to the command line.
function varargout = GUI_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
%% Objects Creation Functions
% Executes during object creation,
%after setting all properties.
function Video_CreateFcn(hObject, eventdata, handles)
function Vid_Path_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,‘BackgroundColor’),…
get(0,‘defaultUicontrolBackgroundColor’))
set(hObject,‘BackgroundColor’,‘white’);
end
function Slider_CreateFcn(hObject, eventdata, handles)
if isequal(get(hObject,‘BackgroundColor’), get(0,‘defaultUicontrolBackgroundColor’))
set(hObject,‘BackgroundColor’,[.9 .9 .9]);
end
function Slider_edit_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,‘BackgroundColor’), get(0,‘defaultUicontrolBackgroundColor’))
set(hObject,‘BackgroundColor’,‘white’);
end
function Speed_CreateFcn(hObject, eventdata, handles)
if isequal(get(hObject,‘BackgroundColor’), get(0,‘defaultUicontrolBackgroundColor’))
set(hObject,‘BackgroundColor’,[.9 .9 .9]);
end
function Mark_in_edit_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,‘BackgroundColor’), get(0,‘defaultUicontrolBackgroundColor’))
set(hObject,‘BackgroundColor’,‘white’);
end
function Mark_out_edit_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,‘BackgroundColor’), get(0,‘defaultUicontrolBackgroundColor’))
set(hObject,‘BackgroundColor’,‘white’);
end
function Select_Target_CreateFcn(hObject, eventdata, handles)
function Target_CreateFcn(hObject, eventdata, handles)
function Radius_edit_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,‘BackgroundColor’), get(0,‘defaultUicontrolBackgroundColor’))
set(hObject,‘BackgroundColor’,‘white’);
end
function F_thresh_edit_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,‘BackgroundColor’), get(0,‘defaultUicontrolBackgroundColor’))
set(hObject,‘BackgroundColor’,‘white’);
end
function Max_iter_edit_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,‘BackgroundColor’), get(0,‘defaultUicontrolBackgroundColor’))
set(hObject,‘BackgroundColor’,‘white’);
end
function Similarity_Plot_CreateFcn(hObject, eventdata, handles)
%% Close Button Callback
function Close_Callback(hObject, eventdata, handles)
% setappdata(handles.MeanShift,‘mydata’,matrices);
display ‘GUI closed. Thanks for using it. 😃’
close(handles.MeanShift);
%% Video Input Callbacks
function Browse_Callback(hObject, eventdata, handles)
[FileName,PathName] = uigetfile({‘.avi’,'(.avi) AVI video file’},…
‘Select input AVI video…’);
if FileName~=0
set(handles.Vid_Path,‘String’,strcat(PathName,FileName));
Vid_Path_Callback(handles.Vid_Path,[], handles);
end
function Vid_Path_Callback(hObject, eventdata, handles)
Path = get(hObject,‘String’);
if exist(Path,‘file’)==2
L = length(Path);
if L>3
extension = Path(L-3:L);
if strcmpi(extension,‘.avi’)==1
set(hObject,‘String’,…
‘Importing video, be patient…’,…
‘ForegroundColor’,‘red’,…
‘FontWeight’,‘bold’);
drawnow;
[handles.lngth,handles.height,handles.width,…
handles.Movie]=Import_mov(Path);
set(hObject,‘String’,Path,…
‘ForegroundColor’,‘black’,…
‘FontWeight’,‘normal’);
for i=L👎1
if strcmp(Path(i),‘’)==1
break;
end
end
handles.FileName = Path(L-i:L-3);
Video_Init(hObject,handles);
end
end
end
%% Video Initialization
function Video_Init(hObject,handles)
handles.indx_start_frame = 1;
handles.indx_end_frame = handles.lngth;
guidata(hObject,handles);
set(handles.Play,‘Enable’,‘on’);
set(handles.Speed,‘Enable’,‘on’);
set(handles.Slider,‘Min’,1,‘Max’,handles.lngth,…
‘Value’,1,‘SliderStep’,[0.01 0.1],‘Enable’,‘on’);
Video_Callback(handles.Video,[],handles);
set(handles.Slider_edit,‘Enable’,‘on’,‘String’,1);
set(handles.Mark_in,‘Enable’,‘on’);
set(handles.Mark_out,‘Enable’,‘on’);
set(handles.Mark_in_edit,‘Enable’,‘on’,‘String’,1);
set(handles.Mark_out_edit,‘Enable’,‘on’,…
‘String’,num2str(handles.lngth));
set(handles.Crop,‘Enable’,‘on’);
Set_Mark_in_pointer(handles.Mark_in_pointer,1,handles);
Set_Mark_in_pointer(handles.Mark_in_edit,1,handles);
Set_Mark_out_pointer(handles.Mark_out_pointer,…
handles.lngth,handles);
Set_Mark_out_pointer(handles.Mark_out_edit,…
handles.lngth,handles);
Disable_Parameters_Panels(handles);
Target_Init(handles);
%% Disable parameters access while no target selected
function Disable_Parameters_Panels(handles)
set(handles.Uniform,‘Enable’,‘off’);
set(handles.Triangular,‘Enable’,‘off’);
set(handles.Epanechnikov,‘Enable’,‘off’);
set(handles.Gaussian,‘Enable’,‘off’);
set(handles.Radius_edit,‘Enable’,‘off’);
set(handles.F_thresh_edit,‘Enable’,‘off’);
set(handles.Max_iter_edit,‘Enable’,‘off’);
set(handles.Start,‘Enable’,‘off’);
⛄三、运行结果
⛄四、matlab版本及参考文献
1 matlab版本
2014a
2 参考文献
[1]陈浩,方勇,朱大洲,王成,陈子龙.基于蚁群算法的玉米植株热红外图像边缘检测[J].农机化研究. 2015,37(06)
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 元胞自动机方面
交通流 人群疏散 病毒扩散 晶体生长
10 雷达方面
卡尔曼滤波跟踪、航迹关联、航迹融合