当前位置 : 主页 > 编程语言 > python >

【图像分割】基于哈里斯鹰优化多阈值实现图像分割附matlab代码

来源:互联网 收集:自由互联 发布时间:2022-06-15
1 简介 一种基于哈里斯鹰优化算法图像分割方法,包括:步骤1:获取待分割图像的灰度值范围;步骤2:根据所述图像的灰度值范围利用哈里斯鹰优化算法得到待分割图像的最佳阈值;步骤3:根据



1 简介

一种基于哈里斯鹰优化算法图像分割方法,包括:步骤1:获取待分割图像的灰度值范围;步骤2:根据所述图像的灰度值范围利用哈里斯鹰优化算法得到待分割图像的最佳阈值;步骤3:根据所述图像分割的最佳阈值,对待分割图像进行分割.本发明是一种新的基于哈里斯鹰与S熵的图像分割方法,相比于其他经典优化算法解决多阈值图像分割的问题,具有分割图像质量更高和分割结果更为稳定的优点.

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('哈里斯鹰优化阈值分割后的图')
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 仿真结果

【图像分割】基于哈里斯鹰优化多阈值实现图像分割附matlab代码_优化算法

【图像分割】基于哈里斯鹰优化多阈值实现图像分割附matlab代码_优化算法_02

4 参考文献

[1]张光斌, 王运, 赵程程,等. 一种基于哈里斯鹰优化算法的图像分割方法:, CN110827299A[P]. 2020.

博主简介:擅长智能优化算法、神经网络预测、信号处理、元胞自动机、图像处理、路径规划、无人机等多种领域的Matlab仿真,相关matlab代码问题可私信交流。

部分理论引用网络文献,若有侵权联系博主删除。

【图像分割】基于哈里斯鹰优化多阈值实现图像分割附matlab代码_优化算法_03

【图像分割】基于哈里斯鹰优化多阈值实现图像分割附matlab代码_优化算法_04

上一篇:Python感悟-1
下一篇:没有了
网友评论