【元胞自动机】基于matlab元胞自动机图像处理【含Matlab源码 234期 】

本文介绍了元胞自动机的基本概念、发展历史、变化规则以及在物理模拟和生物模拟中的应用。通过MATLAB编程展示了如何实现一维和二维元胞自动机,如交通规则和生命游戏,并探讨了元胞自动机在交通流和人群疏散等领域的应用。此外,还提供了一部分源代码供读者参考和学习。
摘要由CSDN通过智能技术生成

✅博主简介:热爱科研的Matlab仿真开发者,修心和技术同步精进,Matlab项目合作可私信。
🍎个人主页:海神之光
🏆代码获取方式:
海神之光Matlab王者学习之路—代码获取方式
⛳️座右铭:行百里者,半于九十。

更多Matlab仿真内容点击👇
Matlab图像处理(进阶版)
路径规划(Matlab)
神经网络预测与分类(Matlab)
优化求解(Matlab)
语音处理(Matlab)
信号处理(Matlab)
车间调度(Matlab)

⛄一、元胞自动机简介

1 元胞自动机发展历程
最初的元胞自动机是由冯 · 诺依曼在 1950 年代为模拟生物 细胞的自我复制而提出的. 但是并未受到学术界重视.
1970 年, 剑桥大学的约翰 · 何顿 · 康威设计了一个电脑游戏 “生命游戏” 后, 元胞自动机才吸引了科学家们的注意.

1983 年 S.Wolfram 发表了一系列论文. 对初等元胞机 256 种 规则所产生的模型进行了深入研究, 并用熵来描述其演化行 为, 将细胞自动机分为平稳型, 周期型, 混沌型和复杂型.

2 对元胞自动机的初步认识
元胞自动机(CA)是一种用来仿真局部规则和局部联系的方法。典型的元胞自动机是定义在网格上的,每一个点上的网格代表一个元胞与一种有限的状态。变化规则适用于每一个元胞并且同时进行。典型的变化规则,决定于元胞的状态,以及其( 4 或 8 )邻居的状态。

3 元胞的变化规则&元胞状态
典型的变化规则,决定于元胞的状态,以及其( 4 或 8 )邻居的状态。

4 元胞自动机的应用
元胞自动机已被应用于物理模拟,生物模拟等领域。

5 元胞自动机的matlab编程
结合以上,我们可以理解元胞自动机仿真需要理解三点。一是元胞,在matlab中可以理解为矩阵中的一点或多点组成的方形块,一般我们用矩阵中的一点代表一个元胞。二是变化规则,元胞的变化规则决定元胞下一刻的状态。三是元胞的状态,元胞的状态是自定义的,通常是对立的状态,比如生物的存活状态或死亡状态,红灯或绿灯,该点有障碍物或者没有障碍物等等。

6 一维元胞自动机——交通规则
定义:
6.1 元胞分布于一维线性网格上.
6.2 元胞仅具有车和空两种状态.
在这里插入图片描述
7 二维元胞自动机——生命游戏
定义:
7.1 元胞分布于二维方型网格上.
7.2 元胞仅具有生和死两种状态.
在这里插入图片描述
元胞状态由周围八邻居决定.
规则:
在这里插入图片描述
骷髅:死亡;笑脸:生存
周围有三个笑脸,则中间变为笑脸
少于两个笑脸或者多于三个,中间则变死亡。

8 什么是元胞自动机
离散的系统: 元胞是定义在有限的时间和空间上的, 并且元 胞的状态是有限.
动力学系统: 元胞自动机的举止行为具有动力学特征.
简单与复杂: 元胞自动机用简单规则控制相互作用的元胞 模拟复杂世界.

在这里插入图片描述
9 构成要素
在这里插入图片描述
(1)元胞 (Cell)
在这里插入图片描述
元胞是元胞自动机基本单元:
状态: 每一个元胞都有记忆贮存状态的功能.
离散: 简单情况下, 元胞只有两种可能状态; 较复杂情况下, 元胞具有多种状态.
更新: 元胞的状态都安照动力规则不断更新.
(2)网格 (Lattice)
不同维网格
在这里插入图片描述
常用二维网格
在这里插入图片描述
(3)邻居 (Neighborhood)
在这里插入图片描述
(4)边界 (Boundary)
在这里插入图片描述
反射型:以自己作为边界的状态
吸收型:不管边界(车开到边界就消失)

(5)规则(状态转移函数)
定义:根据元胞当前状态及其邻居状况确定下一时刻该元胞状态的动力学函数, 简单讲, 就是一个状态转移函数.
分类 :
总和型: 某元胞下时刻的状态取决于且仅取决于它所有邻居 的当前状态以及自身的当前状态.
合法型: 总和型规则属于合法型规则. 但如果把元胞自动机 的规则限制为总和型, 会使元胞自动机具有局限性.
(6)森林火灾
在这里插入图片描述
绿色:树木;红色:火;黑色:空地。
三种状态循环转化:
树:周围有火或者被闪电击中就变成火。
空地:以概率p变为树木
理性分析:红为火;灰为空地;绿是树
在这里插入图片描述
元胞三种状态的密度和为1
在这里插入图片描述
火转化为空地的密度等于空地转换为树的密度(新长出来的树等于烧没的树)
在这里插入图片描述
f是闪电的概率:远远小于树生成的概率;T s m a x T_{smax}T smax
​是一大群树被火烧的时间尺度
程序实现
周期性边界条件
购进啊
在这里插入图片描述
其中的数字为编号
构建邻居矩阵
在这里插入图片描述
上面矩阵中的数字编号,对应原矩阵相同位置编号的上邻居编号,一 一对应
同样道理:
在这里插入图片描述
(7)交通概念
车距和密度
在这里插入图片描述
流量方程
在这里插入图片描述
守恒方程
在这里插入图片描述
时空轨迹(横轴是空间纵轴为时间)
在这里插入图片描述
红线横线与蓝色交点表示每个时间车的位置。
如果是竖线则表示车子在该位置对应的时间

宏观连续模型:
在这里插入图片描述
最常用的规则:
在这里插入图片描述
红色条表示速度是满的。

1 加速规则:不能超过v m a x ( 2 格 / s ) v_{max}(2格/s)v
max(2格/s)
2 防止碰撞:不能超过车距

理论分析:
在这里插入图片描述
结果分析: 密度与流量
在这里插入图片描述
第一个图:横坐标是归一化后的密度,纵坐标是车流量。第二个图:理论值与CA的结果

结果分析: 时空轨迹
在这里插入图片描述
中间的深色区域是交通堵塞的区域。

⛄二、部分源代码

function varargout = ES(varargin)
% ES MATLAB code for ES.fig
% ES, by itself, creates a new ES or raises the existing
% singleton*.
%
% H = ES returns the handle to a new ES or the handle to
% the existing singleton*.
%
% ES(‘CALLBACK’,hObject,eventData,handles,…) calls the local
% function named CALLBACK in ES.M with the given input arguments.
%
% ES(‘Property’,‘Value’,…) creates a new ES or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before ES_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to ES_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE’s Tools menu. Choose “GUI allows only one
% instance to run (singleton)”.
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help ES

% Last Modified by GUIDE v2.5 24-Nov-2014 16:51:08

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct(‘gui_Name’, mfilename, …
‘gui_Singleton’, gui_Singleton, …
‘gui_OpeningFcn’, @ES_OpeningFcn, …
‘gui_OutputFcn’, @ES_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 ES is made visible.
function ES_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to ES (see VARARGIN)

% Choose default command line output for ES
handles.output = hObject;
handles.Img = 0;
handles.ParentImg = 0;
handles.OffspringImg = 0;
handles.Parent = cell(1, 8);
handles.Parent{1} = zeros(1, 3); % Birth
handles.Parent{2} = zeros(1, 3); % Level
handles.Parent{3} = zeros(1, 3); % number of Pattern Pos
handles.Parent{4} = cell(1, 3); % PosH
handles.Parent{5} = cell(1, 3); % PosW
handles.Parent{6} = zeros(1, 3); % Cell Generation
handles.Parent{7} = cell(1, 3); % Pattern
handles.Offspring = cell(1, 8);
handles.Offspring{1} = zeros(1, 3); % Birth
handles.Offspring{2} = zeros(1, 3); % Level
handles.Offspring{3} = zeros(1, 3); % number of Pattern Pos
handles.Offspring{4} = cell(1, 3); % PosH
handles.Offspring{5} = cell(1, 3); % PosW
handles.Offspring{6} = zeros(1, 3); % Cell Generation
handles.Offspring{7} = cell(1, 3); % Pattern
handles.Boundary = cell(1, 7); % Birth, Level, # of CellBlocks, MinCAG, MaxCAG, Image Size
handles.GenerationCount = 0;
if exist(‘iES’, ‘dir’) ~= 7
mkdir(‘iES’);
end
% Update handles structure
guidata(hObject, handles);

% UIWAIT makes ES wait for user response (see UIRESUME)
% uiwait(handles.figure1);

% — Outputs from this function are returned to the command line.
function varargout = ES_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;

function BirthVal_Callback(hObject, eventdata, handles)
% hObject handle to BirthVal (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,‘String’) returns contents of BirthVal as text
% str2double(get(hObject,‘String’)) returns contents of BirthVal as a double

% — Executes during object creation, after setting all properties.
function BirthVal_CreateFcn(hObject, eventdata, handles)
% hObject handle to BirthVal (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,‘BackgroundColor’), get(0,‘defaultUicontrolBackgroundColor’))
set(hObject,‘BackgroundColor’,‘white’);
end

function LevelVal_Callback(hObject, eventdata, handles)
% hObject handle to LevelVal (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,‘String’) returns contents of LevelVal as text
% str2double(get(hObject,‘String’)) returns contents of LevelVal as a double

% — Executes during object creation, after setting all properties.
function LevelVal_CreateFcn(hObject, eventdata, handles)
% hObject handle to LevelVal (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,‘BackgroundColor’), get(0,‘defaultUicontrolBackgroundColor’))
set(hObject,‘BackgroundColor’,‘white’);
end

function CellBlocksVal_Callback(hObject, eventdata, handles)
% hObject handle to CellBlocksVal (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,‘String’) returns contents of CellBlocksVal as text
% str2double(get(hObject,‘String’)) returns contents of CellBlocksVal as a double

% — Executes during object creation, after setting all properties.
function CellBlocksVal_CreateFcn(hObject, eventdata, handles)
% hObject handle to CellBlocksVal (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,‘BackgroundColor’), get(0,‘defaultUicontrolBackgroundColor’))
set(hObject,‘BackgroundColor’,‘white’);
end

function MinCAGVal_Callback(hObject, eventdata, handles)
% hObject handle to MinCAGVal (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,‘String’) returns contents of MinCAGVal as text
% str2double(get(hObject,‘String’)) returns contents of MinCAGVal as a double

% — Executes during object creation, after setting all properties.
function MinCAGVal_CreateFcn(hObject, eventdata, handles)
% hObject handle to MinCAGVal (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,‘BackgroundColor’), get(0,‘defaultUicontrolBackgroundColor’))
set(hObject,‘BackgroundColor’,‘white’);
end

function MaxCAGVal_Callback(hObject, eventdata, handles)
% hObject handle to MaxCAGVal (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,‘String’) returns contents of MaxCAGVal as text
% str2double(get(hObject,‘String’)) returns contents of MaxCAGVal as a double

% — Executes during object creation, after setting all properties.
function MaxCAGVal_CreateFcn(hObject, eventdata, handles)
% hObject handle to MaxCAGVal (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,‘BackgroundColor’), get(0,‘defaultUicontrolBackgroundColor’))
set(hObject,‘BackgroundColor’,‘white’);
end

% — Executes on button press in ImgRead.
function ImgRead_Callback(hObject, eventdata, handles)
% hObject handle to ImgRead (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% [filename, user_canceled] = imgetfile;
% if user_canceled
% return;
% end
filename = ‘lenna.png’;
Img = imread(filename);
handles.Img = Img;
axes(handles.Original);
image(double(handles.Img)/255);
guidata(hObject, handles);

% — Executes on button press in Sellambda.
function Sellambda_Callback(hObject, eventdata, handles)
% hObject handle to Sellambda (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
imwrite(handles.ParentImg, [‘iEA/G’, num2str(handles.GenerationCount), ‘.jpg’]);
[handles.Offspring, cc] = Mutation(handles.Parent, handles.Boundary);
guidata(hObject, handles);
offspring = handles.ParentImg;
[offspring(:, :, cc), ta, tb, tc, td, te] = GUILogicRule(handles.Img, cc, handles.Offspring{1}(cc), handles.Offspring{2}(cc), handles.Offspring{3}(cc), handles.Offspring{6}(cc), 1, handles.Offspring{4}{cc}, handles.Offspring{5}{cc}, handles.Offspring{7}{cc});
axes(handles.mu);
image(offspring);
handles.GenerationCount = handles.GenerationCount +1;
handles.OffspringImg = offspring;
guidata(hObject, handles);
set(handles.Generation, ‘string’, strcat('Generation: ', num2str(handles.GenerationCount)));

% — Executes on button press in Selmu.
function Selmu_Callback(hObject, eventdata, handles)
% hObject handle to Selmu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
imwrite(handles.OffspringImg, [‘iEA/G’, num2str(handles.GenerationCount), ‘.jpg’]);
[handles.Parent, cc] = Mutation(handles.Offspring, handles.Boundary);
guidata(hObject, handles);
Parent = handles.OffspringImg;
[Parent(:, :, cc), ta, tb, tc, td, te] = GUILogicRule(handles.Img, cc, handles.Parent{1}(cc), handles.Parent{2}(cc), handles.Parent{3}(cc), handles.Parent{6}(cc), 1, handles.Parent{4}{cc}, handles.Parent{5}{cc}, handles.Parent{7}{cc});
axes(handles.lambda);
image(Parent);
handles.GenerationCount = handles.GenerationCount +1;
handles.ParentImg = Parent;
guidata(hObject, handles);
set(handles.Generation, ‘string’, strcat('Generation: ', num2str(handles.GenerationCount)));

% — Executes on button press in Start.
function Start_Callback(hObject, eventdata, handles)
% hObject handle to Start (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles.GenerationCount = 1;
Parent = zeros(size(handles.Img));
Sz = size(handles.Img);
Birth = str2double(get(handles.BirthVal, ‘string’));
Level = str2double(get(handles.LevelVal, ‘string’));
NumCellBlocks = str2double(get(handles.CellBlocksVal, ‘string’));
MinCAG = str2double(get(handles.MinCAGVal, ‘string’));
MaxCAG = str2double(get(handles.MaxCAGVal, ‘string’));
for cc=1:3
CellGen = randi([MinCAG, MaxCAG]);
PosH = randi([1, Sz(1)], 1, NumCellBlocks);
PosW = randi([1, Sz(2)], 1, NumCellBlocks);
[Parent(:, :, cc), handles.Parent{6}(cc), handles.Parent{1}(cc), handles.Parent{2}(cc), handles.Parent{3}(cc), handles.Parent{7}{cc}] = GUILogicRule(handles.Img, cc, Birth, Level, NumCellBlocks, CellGen, 0, PosH, PosW, 0);
handles.Parent{4}{cc} = PosH;
handles.Parent{5}{cc} = PosW;
guidata(hObject, handles);
end
handles.Boundary{1} = Birth;
handles.Boundary{2} = Level;
handles.Boundary{3} = NumCellBlocks;
handles.Boundary{4} = MinCAG;
handles.Boundary{5} = MaxCAG;
handles.Boundary{6} = Sz(1);
handles.Boundary{7} = Sz(2);
guidata(hObject, handles);
handles.Offspring = Mutation(handles.Parent, handles.Boundary);
guidata(hObject, handles);
offspring = zeros(Sz);
for cc=1:3
[offspring(:, :, cc), ta, tb, tc, td, te] = GUILogicRule(handles.Img, cc, handles.Offspring{1}(cc), handles.Offspring{2}(cc), handles.Offspring{3}(cc), handles.Offspring{6}(cc), 1, handles.Offspring{4}{cc}, handles.Offspring{5}{cc}, handles.Offspring{7}{cc});
end
handles.ParentImg = Parent;
handles.OffspringImg = offspring;
guidata(hObject, handles);
axes(handles.lambda);
image(Parent);
axes(handles.mu);
image(offspring);
set(handles.Generation, ‘string’, strcat('Generation: ', num2str(handles.GenerationCount)));

⛄三、运行结果

在这里插入图片描述

⛄四、matlab版本及参考文献

1 matlab版本
2014a

2 参考文献
[1]党珊,蒋太刚,巫承军.基于元胞自动机方法的消防疏散仿真研究[J].现代电子技术. 2022,45(21)
[2]帅斌,秦梦瑶,许旻昊.基于元胞自动机的高速铁路列车运行仿真研究[J].计算机仿真. 2022,39(08)
[3]张睿洋.元胞自动机在两类传染病模型中的应用[J].现代信息科技. 2022,6(10)

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 雷达方面
卡尔曼滤波跟踪、航迹关联、航迹融合

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

海神之光

有机会获得赠送范围1份代码

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值