1 简介
提出了基于粒子群优化(PSO)与引力搜索(GSA)混合算法(PSOGSA)的多阈值图像分割方法来解决图像阈值搜寻过程中单一优化算法局部搜索能力不强的问题.在阈值寻优过程中提高群体多样性,增强了全局搜索能力;采用了全局最优解的正态变异策略,扩展了全局最优的搜索区域,避免了算法的早熟收敛.在此基础上,实现了基于粒子群与引力搜索混合算法的多阈值图像分割方法.最后,使用本方法对复杂多目标图像进行了多阈值分割实验,并与引力搜索算法和萤火虫算法进行了比较.实验结果表明,本文方法的分割精度优于引力搜索算法与萤火虫算法,其分割目标函数值在连续运行时的标准差降低了90%以上,是一种精度高,稳定性强的多阈值图像分割方法.
2 部分代码
clear all
close all
clc
% Parameter initialization
% I = imread('Aeroplane.tiff');
I = imread('Cameraman.tiff');
level = 5; %% Threshold = level-1
%
N_PAR = level; %number of thresholds (number of levels-1) (dimensiones)
dim = N_PAR;
%
n = 15; % Size of the swarm " no of objects " %%% Default (n = 15)
Max_Iteration = 300; % Maximum number of "iterations" %%% Default (Max_Iteration = 300)
%
if size(I,3) == 1 %grayscale image
[n_countR, x_valueR] = imhist(I(:,:,1));
end
Nt = size(I,1) * size(I,2);
% % Lmax indicated color segments 0 - 256
Lmax = 256; %256 different maximum levels are considered in an image (i.e., 0 to 255)
for i = 1:Lmax
if size(I,3) == 1
%grayscale image
probR(i) = n_countR(i) / Nt;
end
end
if size(I,3) == 1
up = ones(n,dim) * Lmax;
low = ones(n,dim);
end
tic
RunNo = 1;
for k = [ 1 : RunNo ]
[CPSOGSA_bestit,CPSOGSA_bestF,CPSOGSA_Fit_bests]= CPSOGSA(I, Lmax, n,Max_Iteration,low,up,dim, level, probR);
BestSolutions1(k) = CPSOGSA_bestF;
disp(['Run # ' , num2str(k),'::' 'Best estimates =',num2str(CPSOGSA_bestit)]); % CPSOGSA
end
% /* Boxplot Analysis */
figure
boxplot([BestSolutions1'],{'CPSOGSA'});
color = [([1 0 0])];
h = findobj(gca,'Tag','Box');
for j=1:length(h)
patch(get(h(j),'XData'),get(h(j),'YData'),color(j));
end
title ('\fontsize{15}\bf Aeroplane (k=2)');
% % title ('\fontsize{15}\bf Cameraman (k=2)');
xlabel('\fontsize{15}\bf Algorithms');
ylabel('\fontsize{15}\bf Best Fitness Values');
box on
% % %
% /* Graphical Analysis*/
figure
plot(CPSOGSA_Fit_bests,'DisplayName','CPSOGSA','Color','b','LineStyle','-','LineWidth',3);
disp( ['Time_CPSOGSA =', num2str(toc)]);
title ('\fontsize{15}\bf Aeroplane (k=2)'); % k=2,4,6,8,10
% % title ('\fontsize{15}\bf Cameraman (k=2)');
xlabel('\fontsize{15}\bf Iterations');
ylabel('\fontsize{15}\bf Fitness values');
legend('\fontsize{12}\bf CPSOGSA');
%
%
gBestR = sort(CPSOGSA_bestit);
Iout = imageGRAY(I,gBestR);
Iout2 = mat2gray(Iout);
% % Show results on images
figure
imshow(Iout)
figure
imshow(I)
% % Show results
intensity = gBestR(1:dim-1);
STDR = std(CPSOGSA_Fit_bests) %Standard deviation of fitness values
MSEV = MSE(I, Iout) %Mean Square Error
PSNRV = PSNR(I, Iout) %PSNR between original image I and the segmented image Iout
SSIMV = ssim (I, Iout) %SSIM Quality Measure
FSIMV = FeatureSIM (I, Iout) %FSIM Quality Measure
Best_Fitness_Value= CPSOGSA_Fit_bests(k) %Best fitness
% % Plot the threshold values over the histogram
figure
plot(probR)
hold on
vmax = max(probR);
for i = 1:dim-1
line([intensity(i), intensity(i)],[0 vmax],[1 1],'Color','r','Marker','.','LineStyle','-')
title ('\fontsize{15}\bf Aeroplane (k=2)');
% title ('\fontsize{15}\bf Cameraman (k=2)');
xlabel('\fontsize{15}\bf Gray level');
ylabel('\fontsize{15}\bf Frequency');
hold off
end
3 仿真结果
4 参考文献
[1]巢渊, 戴敏, 陈恺,等. 基于广义反向粒子群与引力搜索混合算法的多阈值图像分割[J]. 光学精密工程, 2015, 23(3):8.