【图像分割】基于收缩系数的粒子群混合引力搜索算法多级图像阈值分割算法研究附matlab代码

本文涉及的产品
视觉智能开放平台,分割抠图1万点
视觉智能开放平台,视频资源包5000点
视觉智能开放平台,图像资源包5000点
简介: 【图像分割】基于收缩系数的粒子群混合引力搜索算法多级图像阈值分割算法研究附matlab代码


🍎个人主页:
Matlab科研工作室

🍊个人信息:格物致知。

更多Matlab仿真内容点击👇

智能优化算法神经网络预测雷达通信无线传感器  

信号处理图像处理路径规划元胞机器人无人机电力系统

⛄ 内容介绍

图像分割是图像处理中的关键步骤之一。实际上,它处理的是根据像素强度将图像划分为不同的类别。这项工作介绍了一种基于收缩系数的粒子群优化和引力搜索算法 (CPSOGSA) 的新图像分割方法。图像的随机样本充当 CPSOGSA 算法的搜索代理。使用 Kapur 的熵方法确定最佳阈值数量。CPSOGSA 在图像分割中的有效性和适用性是通过将其应用于 USC-SIPI 图像数据库中的五个标准图像,即 Aeroplane、Cameraman、Clock、Lena 和 Pirate 来实现的。采用各种性能指标来研究模拟结果,包括最佳阈值、标准偏差、MSE(均方误差)、运行时间分析、PSNR(峰值信噪比)、最佳适应值计算、收敛图、分段图像图和箱线图分析。此外,图像精度通过使用 SSIM(结构相似性指数测量)和 FSIM(特征相似性指数测量)指标进行基准测试。此外,成对的非参数符号 Wilcoxon 秩和检验用于模拟结果的统计验证。此外,CPSOGSA的实验结果与标准PSO、经典GSA、PSOGSA、SCA(正余弦算法)、SSA(salp swarm算法)、GWO(灰狼优化器)、MFO(蛾焰优化器)等八种不同算法进行了比较和 ABC(人工蜂群)。仿真结果清楚地表明,混合 CPSOGSA 已成功提供最佳的 SSIM、FSIM、

⛄ 部分代码

函数 [FSIM, FSIMc] = FeatureSIM(imageRef, imageDis)

% ================================================= =======================

% FSIM Index with automatic downsampling, Version 1.0

% Copyright(c) 2010 张林、张磊、牟璇琴、张大卫



[行,列] = 大小(imageRef(:,:,1));

I1 = 一个(行,列);

I2 = 一个(行,列);

Q1 = 一个(行,列);

Q2 = 一个(行,列);


if ndims(imageRef) == 3 %图像是彩色的

   Y1 = 0.299 * double(imageRef(:,:,1)) + 0.587 * double(imageRef(:,:,2)) + 0.114 * double(imageRef(:,:,3));

   Y2 = 0.299 * double(imageDis(:,:,1)) + 0.587 * double(imageDis(:,:,2)) + 0.114 * double(imageDis(:,:,3));

   I1 = 0.596 * double(imageRef(:,:,1)) - 0.274 * double(imageRef(:,:,2)) - 0.322 * double(imageRef(:,:,3));

   I2 = 0.596 * double(imageDis(:,:,1)) - 0.274 * double(imageDis(:,:,2)) - 0.322 * double(imageDis(:,:,3));

   Q1 = 0.211 * double(imageRef(:,:,1)) - 0.523 * double(imageRef(:,:,2)) + 0.312 * double(imageRef(:,:,3));

   Q2 = 0.211 * double(imageDis(:,:,1)) - 0.523 * double(imageDis(:,:,2)) + 0.312 * double(imageDis(:,:,3));

否则 %images 是灰度的

   Y1 = 图像参考;

   Y2 = 图像分布;

结尾


Y1 = 双(Y1);

Y2 = 双(Y2);

%%%%%%%%%%%%%%%%%%%%%%%%%

% 对图像进行降采样

%%%%%%%%%%%%%%%%%%%%%%%%%

minDimension = min(行,列);

F = max(1,round(minDimension / 256));

aveKernel = fspecial('平均',F);


aveI1 = conv2(I1, aveKernel,'相同');

aveI2 = conv2(I2, aveKernel,'相同');

I1 = aveI1(1:F:行,1:F:列);

I2 = aveI2(1:F:行,1:F:列);


aveQ1 = conv2(Q1, aveKernel,'相同');

aveQ2 = conv2(Q2, aveKernel,'相同');

Q1 = aveQ1(1:F:行,1:F:列);

Q2 = aveQ2(1:F:行,1:F:列);


aveY1 = conv2(Y1, aveKernel,'相同');

aveY2 = conv2(Y2, aveKernel,'相同');

Y1 = aveY1(1:F:行,1:F:列);

Y2 = aveY2(1:F:行,1:F:列);


%%%%%%%%%%%%%%%%%%%%%%%%%

% 计算相位一致性图

%%%%%%%%%%%%%%%%%%%%%%%%%

PC1 = phasecong2(Y1);

PC2 = phasecong2(Y2);


%%%%%%%%%%%%%%%%%%%%%%%%%

% 计算梯度图

%%%%%%%%%%%%%%%%%%%%%%%%%

dx = [3 0 -3; 10 0 -10; 3 0 -3]/16;

dy = [3 10 3; 0 0 0; -3 -10 -3]/16;

IxY1 = conv2(Y1, dx, '相同');    

IyY1 = conv2(Y1, dy, '相同');    

gradientMap1 = sqrt(IxY1.^2 + IyY1.^2);


IxY2 = conv2(Y2, dx, '相同');    

IyY2 = conv2(Y2, dy, '相同');    

gradientMap2 = sqrt(IxY2.^2 + IyY2.^2);


%%%%%%%%%%%%%%%%%%%%%%%%%

% 计算 FSIM

%%%%%%%%%%%%%%%%%%%%%%%%%

T1 = 0.85;%固定的

T2 = 160; %固定的

PCSimMatrix = (2 * PC1 .* PC2 + T1) ./ (PC1.^2 + PC2.^2 + T1);

gradientSimMatrix = (2*gradientMap1.*gradientMap2 + T2) ./(gradientMap1.^2 + gradientMap2.^2 + T2);

PCm = max(PC1, PC2);

SimMatrix = gradientSimMatrix .* PCSimMatrix .* PCm;

FSIM = sum(sum(SimMatrix)) / sum(sum(PCm));


%%%%%%%%%%%%%%%%%%%%%%%%%

% 计算 FSIMc

%%%%%%%%%%%%%%%%%%%%%%%%%

T3 = 200;

T4 = 200;

ISimMatrix = (2 * I1 .* I2 + T3) ./ (I1.^2 + I2.^2 + T3);

QSimMatrix = (2 * Q1 .* Q2 + T4) ./ (Q1.^2 + Q2.^2 + T4);


拉姆达 = 0.03;


SimMatrixC = gradientSimMatrix .* PCSimMatrix .* real((ISimMatrix .* QSimMatrix) .^ lambda) .* PCm;

FSIMc = sum(sum(SimMatrixC)) / sum(sum(PCm));


返回;


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


函数 [ResultPC]=phasecong2(im)

% ================================================= =======================

% 版权所有 (c) 1996-2009 Peter Kovesi

% 计算机科学与软件工程学院

% 西澳大学

% http://www.csse.uwa.edu.au/

%

% Permission is hereby  granted, free of charge, to any  person obtaining a copy

% of this software and associated  documentation files (the "Software"), to deal

% in the Software without restriction, subject to the following conditions:

%

% The above copyright notice and this permission notice shall be included in all

% copies or substantial portions of the Software.

%

% The software is provided "as is", without warranty of any kind.

% References:

%

%     Peter Kovesi, "Image Features From Phase Congruency". Videre: A

%     Journal of Computer Vision Research. MIT Press. Volume 1, Number 3,

%     Summer 1999 http://mitpress.mit.edu/e-journals/Videre/001/v13.html


nscale          = 4;     % Number of wavelet scales.    

norient         = 4;     % Number of filter orientations.

minWaveLength   = 6;     % Wavelength of smallest scale filter.    

mult            = 2;   % Scaling factor between successive filters.    

sigmaOnf        = 0.55;  % Ratio of the standard deviation of the

                            % Gaussian describing the log Gabor filter's

                            % transfer function in the frequency domain

                            % to the filter center frequency.    

dThetaOnSigma   = 1.2;   % Ratio of angular interval between filter orientations    

                            % and the standard deviation of the angular Gaussian

                            % function used to construct filters in the

                            % freq. plane.

k               = 2.0;   % No of standard deviations of the noise

                            % energy beyond the mean at which we set the

                            % noise threshold point.

                            % below which phase congruency values get

                            % penalized.

epsilon         = .0001;                % Used to prevent division by zero.


thetaSigma = pi/norient/dThetaOnSigma;  % Calculate the standard deviation of the

                                       % angular Gaussian function used to

                                       % construct filters in the freq. plane.


[rows,cols] = size(im);

imagefft = fft2(im);              % Fourier transform of image


zero = zeros(rows,cols);

EO = cell(nscale, norient);       % Array of convolution results.                                


estMeanE2n = [];

ifftFilterArray = cell(1,nscale); % Array of inverse FFTs of filters


% Pre-compute some stuff to speed up filter construction


% Set up X and Y matrices with ranges normalised to +/- 0.5

% The following code adjusts things appropriately for odd and even values

% of rows and columns.

if mod(cols,2)

   xrange = [-(cols-1)/2:(cols-1)/2]/(cols-1);

else

   xrange = [-cols/2:(cols/2-1)]/cols;

end


if mod(rows,2)

   yrange = [-(rows-1)/2:(rows-1)/2]/(rows-1);

else

   yrange = [-rows/2:(rows/2-1)]/rows;

end


[x,y] = meshgrid(xrange, yrange);


radius = sqrt(x.^2 + y.^2);       % Matrix values contain *normalised* radius from centre.

theta = atan2(-y,x);              % Matrix values contain polar angle.

                                 % (note -ve y is used to give +ve

                                 % anti-clockwise angles)

 

radius = ifftshift(radius);       % Quadrant shift radius and theta so that filters

theta  = ifftshift(theta);        % are constructed with 0 frequency at the corners.

radius(1,1) = 1;                  % Get rid of the 0 radius value at the 0

                                 % frequency point (now at top-left corner)

                                 % so that taking the log of the radius will

                                 % not cause trouble.


sintheta = sin(theta);

costheta = cos(theta);

clear x; clear y; clear theta;    % save a little memory


% Filters are constructed in terms of two components.

% 1) The radial component, which controls the frequency band that the filter

%    responds to

% 2) The angular component, which controls the orientation that the filter

%    responds to.

% The two components are multiplied together to construct the overall filter.


% Construct the radial filter components...


% First construct a low-pass filter that is as large as possible, yet falls

% away to zero at the boundaries.  All log Gabor filters are multiplied by

% this to ensure no extra frequencies at the 'corners' of the FFT are

% incorporated as this seems to upset the normalisation process when

% calculating phase congrunecy.

lp = lowpassfilter([rows,cols],.45,15);   % Radius .45, 'sharpness' 15


logGabor = cell(1,nscale);


for s = 1:nscale

   wavelength = minWaveLength*mult^(s-1);

   fo = 1.0/wavelength;                  % Centre frequency of filter.

   logGabor{s} = exp((-(log(radius/fo)).^2) / (2 * log(sigmaOnf)^2));  

   logGabor{s} = logGabor{s}.*lp;        % Apply low-pass filter

   logGabor{s}(1,1) = 0;                 % Set the value at the 0 frequency point of the filter

                                         % back to zero (undo the radius fudge).

end


% Then construct the angular filter components...


spread = cell(1,norient);


for o = 1:norient

 angl = (o-1)*pi/norient;           % Filter angle.


 % For each point in the filter matrix calculate the angular distance from

 % the specified filter orientation.  To overcome the angular wrap-around

 % problem sine difference and cosine difference values are first computed

 % and then the atan2 function is used to determine angular distance.


 ds = sintheta * cos(angl) - costheta * sin(angl);    % Difference in sine.

 dc = costheta * cos(angl) + sintheta * sin(angl);    % Difference in cosine.

 dtheta = abs(atan2(ds,dc));                          % Absolute angular distance.

 spread{o} = exp((-dtheta.^2) / (2 * thetaSigma^2));  % Calculate the

                                                      % angular filter component.

end


% The main loop...

EnergyAll(rows,cols) = 0;

AnAll(rows,cols) = 0;


for o = 1:norient                    % For each orientation.

 sumE_ThisOrient   = zero;          % Initialize accumulator matrices.

 sumO_ThisOrient   = zero;      

 sumAn_ThisOrient  = zero;      

 Energy            = zero;      

 for s = 1:nscale,                  % For each scale.

   filter = logGabor{s} .* spread{o};   % Multiply radial and angular

                                        % components to get the filter.

   ifftFilt = real(ifft2(filter))*sqrt(rows*cols);  % Note rescaling to match power

   ifftFilterArray{s} = ifftFilt;                   % record ifft2 of filter

   % Convolve image with even and odd filters returning the result in EO

   EO{s,o} = ifft2(imagefft .* filter);      


   An = abs(EO{s,o});                         % Amplitude of even & odd filter response.

   sumAn_ThisOrient = sumAn_ThisOrient + An;  % Sum of amplitude responses.

   sumE_ThisOrient = sumE_ThisOrient + real(EO{s,o}); % Sum of even filter convolution results.

   sumO_ThisOrient = sumO_ThisOrient + imag(EO{s,o}); % Sum of odd filter convolution results.

   if s==1                                 % Record mean squared filter value at smallest

     EM_n = sum(sum(filter.^2));           % scale. This is used for noise estimation.

     maxAn = An;                           % Record the maximum An over all scales.

   else

     maxAn = max(maxAn, An);

   end

 end                                       % ... and process the next scale


 % Get weighted mean filter response vector, this gives the weighted mean

 % phase angle.


 XEnergy = sqrt(sumE_ThisOrient.^2 + sumO_ThisOrient.^2) + epsilon;  

 MeanE = sumE_ThisOrient ./ XEnergy;

 MeanO = sumO_ThisOrient ./ XEnergy;


 % Now calculate An(cos(phase_deviation) - | sin(phase_deviation)) | by

 % using dot and cross products between the weighted mean filter response

 % vector and the individual filter response vectors at each scale.  This

 % quantity is phase congruency multiplied by An, which we call energy.


 for s = 1:nscale,      

     E = real(EO{s,o}); O = imag(EO{s,o});    % Extract even and odd

                                              % convolution results.

     Energy = Energy + E.*MeanE + O.*MeanO - abs(E.*MeanO - O.*MeanE);

 end


 % Compensate for noise

 % We estimate the noise power from the energy squared response at the

 % smallest scale.  If the noise is Gaussian the energy squared will have a

 % Chi-squared 2DOF pdf.  We calculate the median energy squared response

 % as this is a robust statistic.  From this we estimate the mean.

 % The estimate of noise power is obtained by dividing the mean squared

 % energy value by the mean squared filter value


 medianE2n = median(reshape(abs(EO{1,o}).^2,1,rows*cols));

 meanE2n = -medianE2n/log(0.5);

 estMeanE2n(o) = meanE2n;


 noisePower = meanE2n/EM_n;                       % Estimate of noise power.


 % Now estimate the total energy^2 due to noise

 % Estimate for sum(An^2) + sum(Ai.*Aj.*(cphi.*cphj + sphi.*sphj))


 EstSumAn2 = zero;

 for s = 1:nscale

   EstSumAn2 = EstSumAn2 + ifftFilterArray{s}.^2;

 end


 EstSumAiAj = zero;

 for si = 1:(nscale-1)

   for sj = (si+1):nscale

     EstSumAiAj = EstSumAiAj + ifftFilterArray{si}.*ifftFilterArray{sj};

   end

 end

 sumEstSumAn2 = sum(sum(EstSumAn2));

 sumEstSumAiAj = sum(sum(EstSumAiAj));


 EstNoiseEnergy2 = 2*noisePower*sumEstSumAn2 + 4*noisePower*sumEstSumAiAj;


 tau = sqrt(EstNoiseEnergy2/2);                     % Rayleigh parameter

 EstNoiseEnergy = tau*sqrt(pi/2);                   % Expected value of noise energy

 EstNoiseEnergySigma = sqrt( (2-pi/2)*tau^2 );


 T =  EstNoiseEnergy + k*EstNoiseEnergySigma;       % Noise threshold


 % The estimated noise effect calculated above is only valid for the PC_1 measure.

 % The PC_2 measure does not lend itself readily to the same analysis.  However

 % empirically it seems that the noise effect is overestimated roughly by a factor

 % of 1.7 for the filter parameters used here.


 T = T/1.7;        % Empirical rescaling of the estimated noise effect to

                   % suit the PC_2 phase congruency measure

 Energy = max(Energy - T, zero);          % Apply noise threshold


 EnergyAll = EnergyAll + Energy;

 AnAll = AnAll + sumAn_ThisOrient;

end  % For each orientation

ResultPC = EnergyAll ./ AnAll;

return;



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% LOWPASSFILTER - Constructs a low-pass butterworth filter.

%

% usage: f = lowpassfilter(sze, cutoff, n)

%

% where: sze    is a two element vector specifying the size of filter

%               to construct [rows cols].

%        cutoff is the cutoff frequency of the filter 0 - 0.5

%        n      is the order of the filter, the higher n is the sharper

%               the transition is. (n must be an integer >= 1).

%               Note that n is doubled so that it is always an even integer.

%

%                      1

%      f =    --------------------

%                              2n

%              1.0 + (w/cutoff)

%

% The frequency origin of the returned filter is at the corners.

%

% See also: HIGHPASSFILTER, HIGHBOOSTFILTER, BANDPASSFILTER

%


% Copyright (c) 1999 Peter Kovesi

% School of Computer Science & Software Engineering

% The University of Western Australia

% http://www.csse.uwa.edu.au/

%

% Permission is hereby granted, free of charge, to any person obtaining a copy

% of this software and associated documentation files (the "Software"), to deal

% in the Software without restriction, subject to the following conditions:

%

% The above copyright notice and this permission notice shall be included in

% all copies or substantial portions of the Software.

%

% The Software is provided "as is", without warranty of any kind.


% October 1999

% August  2005 - Fixed up frequency ranges for odd and even sized filters

%                (previous code was a bit approximate)


function f = lowpassfilter(sze, cutoff, n)

   

   if cutoff < 0 || cutoff > 0.5

error('cutoff frequency must be between 0 and 0.5');

   end

   

   if rem(n,1) ~= 0 || n < 1

error('n must be an integer >= 1');

   end


   if length(sze) == 1

rows = sze; cols = sze;

   else

rows = sze(1); cols = sze(2);

   end


   % Set up X and Y matrices with ranges normalised to +/- 0.5

   % The following code adjusts things appropriately for odd and even values

   % of rows and columns.

   if mod(cols,2)

xrange = [-(cols-1)/2:(cols-1)/2]/(cols-1);

   else

xrange = [-cols/2:(cols/2-1)]/cols;

   end


   if mod(rows,2)

yrange = [-(rows-1)/2:(rows-1)/2]/(rows-1);

   else

yrange = [-rows/2:(rows/2-1)]/rows;

   end

   

   [x,y] = meshgrid(xrange, yrange);

   radius = sqrt(x.^2 + y.^2);        % A matrix with every pixel = radius relative to centre.

   f = ifftshift( 1 ./ (1.0 + (radius ./ cutoff).^(2*n)) ); % 过滤器

   返回;

⛄ 运行结果

⛄ 参考文采

相反,SA, & Bala, PS (2021)。基于收缩系数的多级图像阈值粒子群优化和引力搜索算法。专家系统, doi: 10.1111/exsy.12717, Wiley, SCIE (IF = 2.587)

⛄ 完整代码

❤️部分分析引用网络文档,若有版权联盟博主删除
❤️ 关注我领取海量matlab电子书和数学模型资料


相关文章
|
25天前
|
存储 算法 程序员
C 语言递归算法:以简洁代码驾驭复杂逻辑
C语言递归算法简介:通过简洁的代码实现复杂的逻辑处理,递归函数自我调用解决分层问题,高效而优雅。适用于树形结构遍历、数学计算等领域。
|
26天前
|
并行计算 算法 测试技术
C语言因高效灵活被广泛应用于软件开发。本文探讨了优化C语言程序性能的策略,涵盖算法优化、代码结构优化、内存管理优化、编译器优化、数据结构优化、并行计算优化及性能测试与分析七个方面
C语言因高效灵活被广泛应用于软件开发。本文探讨了优化C语言程序性能的策略,涵盖算法优化、代码结构优化、内存管理优化、编译器优化、数据结构优化、并行计算优化及性能测试与分析七个方面,旨在通过综合策略提升程序性能,满足实际需求。
57 1
|
1月前
|
存储 缓存 算法
通过优化算法和代码结构来提升易语言程序的执行效率
通过优化算法和代码结构来提升易语言程序的执行效率
|
1月前
|
算法
分享一些提高二叉树遍历算法效率的代码示例
这只是简单的示例代码,实际应用中可能还需要根据具体需求进行更多的优化和处理。你可以根据自己的需求对代码进行修改和扩展。
|
2天前
|
机器学习/深度学习 算法
基于改进遗传优化的BP神经网络金融序列预测算法matlab仿真
本项目基于改进遗传优化的BP神经网络进行金融序列预测,使用MATLAB2022A实现。通过对比BP神经网络、遗传优化BP神经网络及改进遗传优化BP神经网络,展示了三者的误差和预测曲线差异。核心程序结合遗传算法(GA)与BP神经网络,利用GA优化BP网络的初始权重和阈值,提高预测精度。GA通过选择、交叉、变异操作迭代优化,防止局部收敛,增强模型对金融市场复杂性和不确定性的适应能力。
103 80
|
21天前
|
算法
基于WOA算法的SVDD参数寻优matlab仿真
该程序利用鲸鱼优化算法(WOA)对支持向量数据描述(SVDD)模型的参数进行优化,以提高数据分类的准确性。通过MATLAB2022A实现,展示了不同信噪比(SNR)下模型的分类误差。WOA通过模拟鲸鱼捕食行为,动态调整SVDD参数,如惩罚因子C和核函数参数γ,以寻找最优参数组合,增强模型的鲁棒性和泛化能力。
|
27天前
|
机器学习/深度学习 算法 Serverless
基于WOA-SVM的乳腺癌数据分类识别算法matlab仿真,对比BP神经网络和SVM
本项目利用鲸鱼优化算法(WOA)优化支持向量机(SVM)参数,针对乳腺癌早期诊断问题,通过MATLAB 2022a实现。核心代码包括参数初始化、目标函数计算、位置更新等步骤,并附有详细中文注释及操作视频。实验结果显示,WOA-SVM在提高分类精度和泛化能力方面表现出色,为乳腺癌的早期诊断提供了有效的技术支持。
|
7天前
|
供应链 算法 调度
排队算法的matlab仿真,带GUI界面
该程序使用MATLAB 2022A版本实现排队算法的仿真,并带有GUI界面。程序支持单队列单服务台、单队列多服务台和多队列多服务台三种排队方式。核心函数`func_mms2`通过模拟到达时间和服务时间,计算阻塞率和利用率。排队论研究系统中顾客和服务台的交互行为,广泛应用于通信网络、生产调度和服务行业等领域,旨在优化系统性能,减少等待时间,提高资源利用率。
|
14天前
|
存储 算法
基于HMM隐马尔可夫模型的金融数据预测算法matlab仿真
本项目基于HMM模型实现金融数据预测,包括模型训练与预测两部分。在MATLAB2022A上运行,通过计算状态转移和观测概率预测未来值,并绘制了预测值、真实值及预测误差的对比图。HMM模型适用于金融市场的时间序列分析,能够有效捕捉隐藏状态及其转换规律,为金融预测提供有力工具。
|
23天前
|
算法
基于GA遗传算法的PID控制器参数优化matlab建模与仿真
本项目基于遗传算法(GA)优化PID控制器参数,通过空间状态方程构建控制对象,自定义GA的选择、交叉、变异过程,以提高PID控制性能。与使用通用GA工具箱相比,此方法更灵活、针对性强。MATLAB2022A环境下测试,展示了GA优化前后PID控制效果的显著差异。核心代码实现了遗传算法的迭代优化过程,最终通过适应度函数评估并选择了最优PID参数,显著提升了系统响应速度和稳定性。

热门文章

最新文章