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

时间:2022-12-22 16:55:15

????个人主页: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

end


if mod(rows,2)

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

else

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.

 % 过滤器

    返回;

⛄ 运行结果

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

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

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

⛄ 参考文采

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

⛄ 完整代码

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