差分进化算法在图像处理中的应用研究(Matlab代码实现)

简介: 差分进化算法在图像处理中的应用研究(Matlab代码实现)

💥1 概述

文献来源:


生物的进化普遍遵循达尔文的“物竞天择、适者生存”的准则,即通过个体之间的选择、交叉和变异来适应自然环境。进化算法就是仿效生物界进化过程的新型优化方法,不依赖与问题的具体特征,具有通用、简单、并行处理等优点,因此被认为是对21世纪的计算机技术有重大影响的关键技术。 差分进化算法提出时间较晚,但其以较强的全局收敛能力、鲁棒性和稳定性迅速成为进化算法领域的研究热点。差分进化算法保留了基于种群的全局搜索策略,采用实数编码、基于差分的简单变异操作和一对一的竞争生存策略,降低了进化操作的复杂性。差分进化算法作为一种高效、简单的并行优化算法,对其进行理论和应用研究具有重要的学术意义。 本文通过对差分进化算法理论基础的研究,针对不同应用问题给出了不同的改进算法。使用差分进化算法解决图像分割问题,并与最大类间方差法作比较分析,试验证明可节省大量时间。在含噪音图像分割问题中,本文使用二次探索改进差分进化算法,提高了算法在进化后期的搜索能力,改善了图像分割的视觉效果。 图像恢复问题是图像处理的重要问题之一。图像恢复问题的主要难点图像信息大,处理速度慢。因此,本文借助差分进化算法的收敛速度快、算法稳定等优点进行图像恢复。在图像恢复过程中算法结合图像特点,随机选取窗口进行交叉和变异操作,取得了较好的结果。  


📚2 运行结果

部分代码:

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');


🌈3 Matlab代码实现

🎉4 参考文献

部分理论来源于网络,如有侵权请联系删除。

[1]赵艳丽. 差分进化算法在图像处理中的应用研究[D].中国石油大学,2010.

目录
打赏
0
0
0
0
78
分享
相关文章
|
7月前
|
【2023高教社杯】D题 圈养湖羊的空间利用率 问题分析、数学模型及MATLAB代码
本文介绍了2023年高教社杯数学建模竞赛D题的圈养湖羊空间利用率问题,包括问题分析、数学模型建立和MATLAB代码实现,旨在优化养殖场的生产计划和空间利用效率。
299 6
【2023高教社杯】D题 圈养湖羊的空间利用率 问题分析、数学模型及MATLAB代码
【2022年华为杯数学建模】B题 方形件组批优化问题 方案及MATLAB代码实现
本文提供了2022年华为杯数学建模竞赛B题的详细方案和MATLAB代码实现,包括方形件组批优化问题和排样优化问题,以及相关数学模型的建立和求解方法。
177 3
【2022年华为杯数学建模】B题 方形件组批优化问题 方案及MATLAB代码实现
【2023五一杯数学建模】 B题 快递需求分析问题 建模方案及MATLAB实现代码
本文介绍了2023年五一杯数学建模竞赛B题的解题方法,详细阐述了如何通过数学建模和MATLAB编程来分析快递需求、预测运输数量、优化运输成本,并估计固定和非固定需求,提供了完整的建模方案和代码实现。
206 0
【2023五一杯数学建模】 B题 快递需求分析问题 建模方案及MATLAB实现代码
MATLAB Simulink 交交变流电路性能研究
MATLAB Simulink 交交变流电路性能研究
118 2
耐震时程曲线,matlab代码,自定义反应谱与地震波,优化源代码,地震波耐震时程曲线
地震波格式转换、时程转换、峰值调整、规范反应谱、计算反应谱、计算持时、生成人工波、时频域转换、数据滤波、基线校正、Arias截波、傅里叶变换、耐震时程曲线、脉冲波合成与提取、三联反应谱、地震动参数、延性反应谱、地震波缩尺、功率谱密度
基于混合整数规划的微网储能电池容量规划(matlab代码)
基于混合整数规划的微网储能电池容量规划(matlab代码)
含多微网租赁共享储能的配电网博弈优化调度(含matlab代码)
含多微网租赁共享储能的配电网博弈优化调度(含matlab代码)
基于Logistic函数的负荷需求响应(matlab代码)
基于Logistic函数的负荷需求响应(matlab代码)
基于分布式优化的多产消者非合作博弈能量共享(Matlab代码)
基于分布式优化的多产消者非合作博弈能量共享(Matlab代码)
基于多目标粒子群算法冷热电联供综合能源系统运行优化(matlab代码)
基于多目标粒子群算法冷热电联供综合能源系统运行优化(matlab代码)