欢迎来到本博客❤️❤️
博主优势:博客内容尽量做到思维缜密,逻辑清晰,为了方便读者。
⛳️座右铭:行百里者,半于九十。
本文目录如下:
目录
1 概述
2 运行结果
3 Matlab代码实现
4 参考文献
文献来源:
生物的进化普遍遵循达尔文的“物竞天择、适者生存”的准则,即通过个体之间的选择、交叉和变异来适应自然环境。进化算法就是仿效生物界进化过程的新型优化方法,不依赖与问题的具体特征,具有通用、简单、并行处理等优点,因此被认为是对21世纪的计算机技术有重大影响的关键技术。 差分进化算法提出时间较晚,但其以较强的全局收敛能力、鲁棒性和稳定性迅速成为进化算法领域的研究热点。差分进化算法保留了基于种群的全局搜索策略,采用实数编码、基于差分的简单变异操作和一对一的竞争生存策略,降低了进化操作的复杂性。差分进化算法作为一种高效、简单的并行优化算法,对其进行理论和应用研究具有重要的学术意义。 本文通过对差分进化算法理论基础的研究,针对不同应用问题给出了不同的改进算法。使用差分进化算法解决图像分割问题,并与最大类间方差法作比较分析,试验证明可节省大量时间。在含噪音图像分割问题中,本文使用二次探索改进差分进化算法,提高了算法在进化后期的搜索能力,改善了图像分割的视觉效果。 图像恢复问题是图像处理的重要问题之一。图像恢复问题的主要难点图像信息大,处理速度慢。因此,本文借助差分进化算法的收敛速度快、算法稳定等优点进行图像恢复。在图像恢复过程中算法结合图像特点,随机选取窗口进行交叉和变异操作,取得了较好的结果。
部分代码:
generationAtBestFit = [0 0];%stores generation and best fitness
spaceSize = size(searchSpace, 1);
totalPixels = sum(searchSpace);
normProba = searchSpace ./ totalPixels;%normalized probabilities
if thresh < 1 || thresh > spaceSize, disp('Thresholds should be in a range of 1 to 256');return;end
%-----Get an initial Fitness
[fitnessX, X] = OtsuFitness(X, spaceSize, totalPixels, normProba);
[val, fittest] = max(fitnessX);
for gen = 1:generations
%-----Mutation and crossover
for p = 1:population
%don't mutate or crossover the one with best fitness
if fittest == p, U(:, p) = X(:, p);continue;end
%Select three vectors for mutation
randX = linspace(1, population, population);randX(p)=[];
px1 = ceil(rand(1,1)*numel(randX));x1 = randX(px1);randX(px1)=[];
px2 = ceil(rand(1,1)*numel(randX));x2 = randX(px2);randX(px2)=[];
px3 = ceil(rand(1,1)*numel(randX));x3 = randX(px3);
mutant = X(:, x1) + round(vBeta.*(X(:, x2) - X(:, x3)));
%---Crossover (will always happen if threshold is 1)
chk = rand(thresh, 1);
chk(ceil(rand(1) * thresh)) = 0;%one compulsory crossover
bothSame = 0;
if mutant == X(:, p), bothSame = 1; end
for cross = 1:thresh
%if vectors end up being exactly similar, re-generate randomly
if bothSame==1, mutant(cross, 1) = floor(minThresh + (maxThresh - minThresh) * rand(1));continue;end
if chk(cross) <= cr && thresh ~= 1,mutant(cross, 1) = X(cross, p);end
end
%Bring thresholds within range by regeneration instead of clamping
mutant(mutant > maxThresh | mutant < minThresh) = floor(minThresh + (maxThresh - minThresh) * rand(1));
U(:, p) = mutant(:);
end
%-----Selection
[fitnessU, U] = OtsuFitness(U, spaceSize, totalPixels, normProba);
for p = 1:population
if fitnessU(p) > fitnessX(p),
X(:, p) = U(:, p);
fitnessX(p) = fitnessU(p);
end
end
[val, fittest] = max(fitnessX);
tempFitStore = [tempFitStore fitnessX(fittest)];
%=======PSO hybrid attempt (does not work well enough)
%if gen > 5,
% %get three X vectors that are closest in fitness to the best X
% tempX = X; tFitnessX = fitnessX;
% tempX(:,fittest) = []; tFitnessX(fittest) = [];
% [v, f] = max(tFitnessX);x1 = tempX(:, f);fitX1=v;tempX(:,f) = [];tFitnessX(f) = [];
% [v, f] = max(tFitnessX);x2 = tempX(:, f);fitX2=v;tempX(:,f) = [];tFitnessX(f) = [];
% [v, f] = max(tFitnessX);x3 = tempX(:, f);fitX3=v;tempX(:,f) = [];tFitnessX(f) = [];
% [xBest, fitXBest] = exploitWithPSO(X(:,fittest), x1, x2, x3, val, fitX1, fitX2, fitX3, spaceSize, totalPixels, normProba, maxThresh, minThresh);
% if fitXBest > fitnessX(fittest),
% X(:,fittest) = xBest;
% fitnessX(fittest) = fitXBest;
% end
%end
%=====end of PSO
%---Store the generation at which best fitness was achieved
if fitnessX(fittest) > generationAtBestFit(2),
generationAtBestFit(1) = gen;
generationAtBestFit(2) = fitnessX(fittest);
end
if generationAtBestFit(1) > fastestGenerationForBestFitness,
fastestGenerationForBestFitness = generationAtBestFit(1);
end
%fprintf('Image %d is max fit. fitness %f. Achived at gen %d\n', fittest, fitnessX(fittest), generationAtBestFit(1));
if fitnessX(fittest) > bestFitnessAmongTrials,
bestFitnessAmongTrials = fitnessX(fittest);
bestThresholdAmongTrials = X(:,fittest);
end
%---decrease beta to lower exploration and favour exploitation
if vBeta > 1/40, vBeta = vBeta - 1/40;end
%if vBeta > 1/(thresh*4), vBeta = vBeta - 1/(4*thresh);end
end %end of generation loop
runtime = [runtime toc];
if bestFitnessAmongTrials > tempBestFitnessAmongTrials,
tempBestFitnessAmongTrials = bestFitnessAmongTrials;
fitStore = tempFitStore;
end
end %end of trial loop
%---DE completed. Now display data
fprintf('mean: ');
mean(runtime)
fprintf('standard deviation: ');
std(runtime)
fprintf('fastestGenerationForBestFitness=%d\n', fastestGenerationForBestFitness);
fprintf('Best fitness achieved until now=%f with thresholds ', bestFitnessAmongTrials);
disp(bestThresholdAmongTrials');
%-----Display multithresholded images of each vector
figure(figNum);clf;figNum=figNum+1;
T = I;
for j = 1:thresh+1
if j == 1,%first bunch
T(I < bestThresholdAmongTrials(j)) = minThresh-1;%0
else
if j > thresh,%last bunch
T(I >= bestThresholdAmongTrials(j-1)) = maxThresh-1;%255
else%everything else
T(I >= bestThresholdAmongTrials(j-1) & I < bestThresholdAmongTrials(j)) = bestThresholdAmongTrials(j-1);
end
end
end
imshow(T);
title('Best thresholded image');
%-----Display fitness graph
figure(figNum);clf;figNum=figNum+1;
plot(linspace(1, gen, gen), fitStore);
xlabel('Generation');ylabel('Fitness');title('Fitness over time');
部分理论来源于网络,如有侵权请联系删除。
[1]赵艳丽. 差分进化算法在图像处理中的应用研究[D].中国石油大学,2010.