【圖像分割】基于哈里斯鷹優(yōu)化多閾值實現(xiàn)圖像分割附matlab代碼
1 簡介
一種基于哈里斯鷹優(yōu)化算法圖像分割方法,包括:步驟1:獲取待分割圖像的灰度值范圍;步驟2:根據(jù)所述圖像的灰度值范圍利用哈里斯鷹優(yōu)化算法得到待分割圖像的最佳閾值;步驟3:根據(jù)所述圖像分割的最佳閾值,對待分割圖像進(jìn)行分割.本發(fā)明是一種新的基于哈里斯鷹與S熵的圖像分割方法,相比于其他經(jīng)典優(yōu)化算法解決多閾值圖像分割的問題,具有分割圖像質(zhì)量更高和分割結(jié)果更為穩(wěn)定的優(yōu)點.
2 部分代碼
%% MCET-HHO
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% An Efficient Harris Hawks-inspired Image Segmentation Method
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear all
clc
close all
%% Initial data
I=imread('rice.png'); ? ?% Load image
[h,nh]=imhist(I); ? ? ? ? ? % Get Histogram
[m,n]=size(I); ? ? ? ? ? ? ?% Image size
L=length(h); ? ? ? ? ? ? ? ?% Lmax levels to segment 0 - 256
Nt=size(I,1) * size(I,2); ? % Total pixels in the image
% Frequency distribution of each intensity level of the histogram 0 - 256
for i=1:L
? ?probI(i)=h(i)/Nt;
end
%% Initial data of the HHO algorithm
nVar=1; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? % Number of thresholds (Th)
VarSize=[1 nVar]; ? ? ? ? ? ? ? ? ? ? ? % Decision Variables in Matrix
VarMin=1; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? % Minimum value of Th
VarMax=255; ? ? ? ? ? ? ? ? ? ? ? ? ? ? % Maximum value of Th
%% Harris Hawks Algorithm Parameters
N=30; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? % Maximum Number of Hawks
T=100; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?% Maximum Number of Iterations
tic
Rabbit_Location=zeros(1,nVar); ? ? ? ? ?% Initialization of the rabbit's location
Rabbit_Energy=inf; ? ? ? ? ? ? ? ? ? ? ?% Initialization of the energy of the rabbit
%% Initialization of the position of the hawks
X=initialization(N,nVar,VarMax,VarMin);
%% Harris Hawks Algorithm Main
CNVG=zeros(1,T);
t=0;????????????????????????????????????%?Counter
? ?CNVG(t)=Rabbit_Energy;
end
%% Image segmentation
Ith=MultiTresh(I,Rabbit_Location);
figure
subplot(122)
imshow(Ith);
title('哈里斯鷹優(yōu)化閾值分割后的圖')
subplot(121)
imshow(I);
title('原圖')
%% Evaluation of the segmentation
%PSNR: Peak Signal to Noise Ratio
PSNR=psnr(Ith, I)
% SSIM: Structural Similarity Index (1, indica una conincidencia perfecta)
SSIM=ssim(I,Ith)
%FSIM: Feature Similarity Index
FSIM=FeatureSIM(I,Ith)
%% Histogram Plot
fitness = Rabbit_Energy
intensity = Rabbit_Location
figure
plot(probI)
hold on
vmax = max(probI);
for i = 1:length(Rabbit_Location)
? ?line([intensity(i), intensity(i)],[0 vmax],[1 1],'Color','r','Marker','.','LineStyle','-');
? ?hold on
end
hold off
3 仿真結(jié)果
4 參考文獻(xiàn)
[1]張光斌, 王運, 趙程程,等. 一種基于哈里斯鷹優(yōu)化算法的圖像分割方法:, CN110827299A[P]. 2020.