【元胞自动机】基于元胞自动机实现艺术图像处理附matlab代码
1 內(nèi)容介紹
元胞自動機變換為我們提供了一個將已知現(xiàn)象和元胞自動機演化聯(lián)系起來的直接方法.它將物理網(wǎng)格空間上的每個點通過元胞自動機變換基映射到元胞自動機空間上,通過元胞自動機空間上的變換系數(shù)揭示出物理空間中很難觀察到的性質(zhì).元胞自動機變換最大的優(yōu)勢是能產(chǎn)生大量的不同性質(zhì)的基函數(shù),這些基函數(shù)可以適應(yīng)已知問題的各種特性,為圖像壓縮,數(shù)據(jù)加密,求解積分方程等方面的應(yīng)用提供一個良好的平臺. 本文先對元胞自動機變換的發(fā)展情況和元胞自動機變換的基本方法作了簡要的介紹,在此基礎(chǔ)上把元胞自動機變換應(yīng)用到圖像處理中?。
2 仿真代碼
function [ opImgCell ] = CAPainting( Img, mu, lambda, Generation, Boundary )
%CAPAINTING Summary of this function goes here
%? ?Detailed explanation goes here
Img = double(Img);
Sz = size(Img);
Pop = cell(1, mu+lambda);
Result = cell(1, mu+lambda);
if exist('Save', 'dir') ~= 7
? ? mkdir('Save');
end
% initialize first population
for i=1:mu+lambda
? ? if i<= mu
? ? ? ? Pop{i} = cell(1, 7);
? ? ? ? Pop{i}{1} = randi([1, Boundary{1}], 1, 3); % Birth
? ? ? ? Pop{i}{2} = randi([1, Boundary{2}], 1, 3); % Level
? ? ? ? Pop{i}{3} = randi([1, Boundary{3}], 1, 3); % number of Pattern Pos
? ? ? ? Pop{i}{6} = randi([Boundary{4}, Boundary{5}], 1, 3); % Cell Generation
? ? ? ? Pop{i}{4} = cell(1, 3); % PosH
? ? ? ? Pop{i}{5} = cell(1, 3); % PosW
? ? ? ? Pop{i}{7} = cell(1, 3); % Pattern
? ? ? ? for j=1:3
? ? ? ? ? ? Pop{i}{4}{j} = randi([1, Boundary{6}], 1, Pop{i}{3}(j));??
? ? ? ? ? ? Pop{i}{5}{j} = randi([1, Boundary{7}], 1, Pop{i}{3}(j));
? ? ? ? ? ? Pop{i}{7}{j} = randi([0, 1],2*Pop{i}{2}(j)+1, 2*Pop{i}{2}(j)+1);
? ? ? ? end
? ? ? ? Result{i} = zeros(Sz);
? ? ? ? for cc=1:3
? ? ? ? ?[Result{i}(:, :, cc), ta, tb, tc, td, te] = GUILogicRule(Img, cc, Pop{i}{1}(cc), Pop{i}{2}(cc), Pop{i}{3}(cc), Pop{i}{6}(cc), 1, Pop{i}{4}{cc}, Pop{i}{5}{cc}, Pop{i}{7}{cc});
? ? ? ? end
? ? else
? ? ? ? Pop{i} = cell(1, 7);
? ? ? ? Result{i} = zeros(Sz);
? ? end
end
% end initialize? ??
Fit = Fitness(Result);
for g=1:Generation
? ? % tournament size = 2;
? ? SelCounter = 1;
? ? selectMutation = zeros(1, mu);
? ? for sel=1:mu
? ? ? ? selectArray = randi([1, mu], 1, 2);
? ? ? ? if Fit(selectArray(1)) > Fit(selectArray(2))
? ? ? ? ? ? selectMutation(SelCounter) = selectArray(1);
? ? ? ? ? ? SelCounter = SelCounter +1;
? ? ? ? else
? ? ? ? ? ? selectMutation(SelCounter) = selectArray(2);
? ? ? ? ? ? SelCounter = SelCounter +1;
? ? ? ? end
? ? end
? ? for mutate=1:lambda
? ? ? ? [Pop{mu+mutate}, cc] = Mutation(Pop{selectMutation(mutate)}, Boundary);
? ? ? ? Result{mu+mutate} = Result{selectMutation(mutate)};
? ? ? ? [Result{mu+mutate}(:, :, cc), ta, tb, tc, td, te] = GUILogicRule(Img, cc, Pop{mu+mutate}{1}(cc), Pop{mu+mutate}{2}(cc), Pop{mu+mutate}{3}(cc), Pop{mu+mutate}{6}(cc), 1, Pop{mu+mutate}{4}{cc}, Pop{mu+mutate}{5}{cc}, Pop{mu+mutate}{7}{cc});
? ? end? ??
? ? Fit = Fitness(Result);
? ? % survivor selection
? ? [Fit,sortIndex] = sort(Fit(:),'descend');?
? ? Fit = [Fit(1:mu)', zeros(1, lambda)];
? ? selectParent = sortIndex(1:mu);? ?
? ? newPop = cell(1, mu+lambda);
? ? newRes = cell(1, mu+lambda);
? ? for wrt=1:mu+lambda
? ? ? ? if wrt <= mu
? ? ? ? ? ? imwrite(Result{wrt}, ['Save/G', num2str(g), 'Parent', num2str(wrt), '.jpg']);
? ? ? ? else
? ? ? ? ? ? imwrite(Result{wrt}, ['Save/G', num2str(g), 'Child', num2str(wrt-mu), '.jpg']);
? ? ? ? end
? ? end
? ? for i=1:mu+lambda
? ? ? ? if i<= mu
? ? ? ? ? ? newPop{i} = Pop{selectParent(i)};
? ? ? ? ? ? newRes{i} = Result{selectParent(i)};
? ? ? ? else
? ? ? ? ? ? newPop{i} = cell(1, 7);
? ? ? ? ? ? newRes{i} = zeros(Sz);
? ? ? ? end
? ? end
? ? Pop = newPop;
? ? Result = newRes;
end
opImgCell = Result;
end
3 運行結(jié)果
4 參考文獻
[1]李輝亮. 基于元胞自動機的數(shù)字圖像處理[D]. 汕頭大學(xué), 2007.
博主簡介:擅長智能優(yōu)化算法、神經(jīng)網(wǎng)絡(luò)預(yù)測、信號處理、元胞自動機、圖像處理、路徑規(guī)劃、無人機等多種領(lǐng)域的Matlab仿真,相關(guān)matlab代碼問題可私信交流。
部分理論引用網(wǎng)絡(luò)文獻,若有侵權(quán)聯(lián)系博主刪除。
?
總結(jié)
以上是生活随笔為你收集整理的【元胞自动机】基于元胞自动机实现艺术图像处理附matlab代码的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 调度队列模型
- 下一篇: matlab构造跟驰模型,基于跟驰模型的