1 Introduction

Threshold image segmentation is a widely used segmentation technology that performs image segmentation based on the information contained in the image gray-level histogram. The gray value difference between the target area and the background area in the image is compared, an appropriate threshold is given to judge the gray value of each pixel in the image belongs to the target region or the background region, so as to segment the image. Nowadays, there are many threshold image segmentation methods, while maximum entropy method [17, 47], inter class variance method(OTSU) [4, 41], cross entropy method [10, 25, 50] and minimum error method [5, 22] are divided according to the selection criteria of threshold. Image segmentation based on entropy is very popular, and entropy can be divided into Shannon entropy [39], tsallis entropy [13], exponential entropy [42, 51] and arimoto entropy [30], etc. According to the dimension of image histogram, it also can be classified into one-dimensional (1-D) histogram, two-dimensional (2-D) histogram [1, 6, 45] and so on.

In the process of image threshold segmentation, the effects of some factors on segmentation results are summarized as follows:

  1. (1)

    The separation between peaks. It is assumed that the gray level of the image composed of target and background has unimodal distribution characteristics. The gray levels of adjacent pixels in the target or background are highly correlated, but the gray levels of pixels at the junction of target and background are very different. Then the image gray histogram can be regarded as a mixture of two single peak histograms corresponding to the target and background respectively. At this time, if the number of the two distributions is close, the standardized mean difference is far enough and the mean square deviation is small enough, the histogram is bimodal, the pixel value that can be used as the bottom of the valley is found as the threshold between the two peaks. Therefore, the farther the wave crest is away, the greater the chance of separating the target from the background.

  2. (2)

    Noise content in the image. Noise will change the gray value of some pixels in the histogram, resulting in imbalance, such as filling the bottom of the histogram and generating new peaks.

  3. (3)

    Relative size of objects and background. When the target is small or large, the peak of the target and the background in the histogram will be quite different, so it is difficult to distinguish the valley bottom, which affects the selection of threshold.

  4. (4)

    The uniformity of illumination and reflection. When the illumination or the image reflection is uneven, the brightness of the target and background will change, and shadow areas may appear around the target. These factors will affect the change of image gray value, thus affecting the distribution of histogram, resulting in poor segmentation effect.

Using entropy as texture feature is an important research theme, many scholars have used entropy as the basis of threshold image segmentation. Liu et al. proposed a novel image thresholding based on 2-D Arimoto Entropy (TDAE), called Ellipsoid Region Search Strategy (ERSS) [30]. Li et al. proposed a parameter adaptive hybrid model for image segmentation, the image’s local entropy was used to establish the index for measuring the image’s gray-level information [26]. Chakraborty et al. proposed an improved version of Fractional Order Darwinian PSO (IFODPSO) for segmenting 3D histogram-based color images at multiple levels of Berkley Segmentation Dataset (BSDS500), Multi-level Massi Entropy (MME) had been chosen as the objective function for finding the threshold values in combination with IFODPSO [7]. Nejad et al. proposed a multi-level thresholding method based on imperialist competition algorithm and Kapur’s entropy [40]. Yan et al. proposed a image segmentation method based on whale optimization algorithm (WOA) and Kapur’s entropy [57]. Lei et al. defined a new form of square rough entropy to measure the roughness in an image, and proposed a corresponding threshold image segmentation algorithm [23]. Moreover, Lin et al. adopted the Tsallis cross-entropy in threshold image segmentation [29].

Only when the most appropriate threshold is found accurately, can the image segmentation be more accurate. Therefore, how to find the appropriate threshold quickly and accurately becomes the key of threshold image segmentation research.

Optimization algorithm based on the swarm intelligence is a bionic algorithm which simulates the behaviors of insects, birds, fish and other wild animals foraging and hunting. There are many well-known algorithms such as particle swarm optimization (PSO) [20], artificial bee colony algorithm (ABC) [18], fruit fly optimization algorithm (FOA) [44], grey wolf optimizer (GWO) [49], chicken swarm optimization (CSO) [36] and the WOA [37] and so on.

In recent years, more and more scholars have used intelligence optimization algorithm to solve image segmentation problems and achieved good results. Some algorithms used in image segmentation are listed in Table 1.

Table 1 The summary of image segmentation based on intelligent optimization algorithms

Sparrow search algorithm (SSA) is a new swarm intelligence optimization algorithm proposed by Xue and Shen [56], it is inspired by the foraging behavior and vigilance behavior of sparrows. The algorithm has strong optimization ability and fast convergence speed. It has been widely investigated by scholars. Yuan et al. proposed a DMPPT control of photovoltaic microgrid based on improved SSA [58]. Liu et al. proposed a modified SSA with application in 3-D route planning for UAV [32]. Zhang et al. proposed a semi-supervised ensemble classifier with an improved SSA and applied it to pulmonary nodule detection [59]. Wang et al. conducted a research on economic optimization of microgrid cluster based on chaos SSA [53]. Gai et al. proposed a parameter-optimized deep belief network (DBN) based on SSA for gear fault severity detection [11]. Kathiroli et al. presented an efficient cluster-based routing model using Sparrow search algorithm derives a fitness function to perform clustering process [19]. Tuerxun et al. used the SSA to optimize the penalty factor and kernel function parameter of SVM and constructed the SSA-SVM wind turbine fault diagnosis model [52].

However, the SSA still has the disadvantage of easy to fall into the local optimal solution in the late iteration. Some scholars have put forward different solutions. Yuan et al. proposed a improved SSA based on the center of gravity reverse learning mechanism, learning coefficient and mutation operator [58]. Zhang et al. adopted sine cosine algorithm and new labor cooperation structure to increase the global optimal solution and convergence performance of SSA [59]. Wang et al. proposed a chaos SSA, which combines Bernoulli chaotic mapping, dynamic adaptive weighting, Cauchy mutation, and reverse learning [53]. Li et al. combined the SSA with direction learning strategy and metropolis criterion of simulated annealing algorithm [24]. Lv et al. improved the SSA by combining with the flight behavior in bird swarm algorithm [33]. Zhou et al. proposed a modified SSA by introducing crossover and mutation [60]. This algorithm has higher convergence rate than the original SSA. Liang et al. modified SSA with combining a homogeneous chaotic system, adaptive inertia weight, and improved boundary constraint [28].

In this research, an improved sparrow search algorithm (ISSA) is proposed which combines Levy flight and nonlinear inertia weight. Nonlinear inertia weight would enhance the local exploration ability and Levy flight would help the algorithm escaping from the local optimum. Then a new image threshold segmentation method is proposed based on ISSA. The gray value of each pixel in the graph and the mean of gray in its field are considered, the 2-D entropy is used as the evaluation function, and the entropy optimization is carried out by ISSA to obtain the threshold corresponding to the maximum entropy. In order to verify the feasibility and effectiveness of ISSA, it is tested on fifteen benchmark functions. Results are compared with some well-known algorithms such as SSA, PSO, GWO, ABC, WOA, CSO, and FOA. In the last, state-of-the-art approaches including ISSA, gold eagle optimizer (GEO) [38], rat swarm optimizer (RSO) [8], transient search optimization (TSO) [46], CRSSA [35], MSCA [48], HHO-PCNN [14], 2D-OTSU [31] and 1D-Exponential entropy [43] are applied to image segmentation. Peak signal-to-noise ratio (PSNR) and feature similarity (FSIM) are used as evaluation indexes for comparison. Experimental results demonstrate the effectiveness of the proposed method.

The main contributions of this paper are:

  1. (1)

    An improved sparrow search algorithm combining Levy flight and nonlinear inertia weight factor is proposed.

  2. (2)

    Compared with PSO, GWO, ABC, WOA, CSO, FOA and SSA, ISSA has better convergence speed, accuracy and robustness.

  3. (3)

    The experimental results show that compared with segmentation methods by GEO, RSO, TSO, CRSSA, MSCA and HHO-PCNN, 2D-OTSU and 1D-Exponential entropy, the segmented images obtained by ISSA and 2-D entropy have excellent peak signal-to-noise ratio and feature similarity.

The remainder of this paper is organized as follows. Section 2 introduces the SSA and the improved method. Section 3 analyzes the convergence of the ISSA. Section 4 proposes the threshold image segmentation based on ISSA and 2-D maximum entropy. Section 5 evaluates the performance of the ISSA and compares the segmentation results for different type of images. Finally, the paper is concluded in Section 6.

2 Improved sparrow search algorithm

2.1 Sparrow search algorithm

Sparrow search algorithm is proposed according to the predatory behavior and vigilant behavior of sparrow population. According to the role of each sparrow in the population, it can be divided into discoverer, entrant and vigilant sparrow.

The discoverers have more energy reserves in the whole population. They are responsible for exploring food for the whole population and guiding the entrants to search for foods. The fitness of the discoverers is better than entrants. In the process of searching for food, if the discoverer detects the danger, it will call to remind other members of the population and move to a new safe area to continue search for foods. In the algorithm, if the fitness of entrant is better than discoverer, the entrant will become discoverer to search for food. The location update formula of the discoverers is described as follows:

$$ {X}_{i,j}^{t+1}=\Big\{{\displaystyle \begin{array}{c}{X}_{i,j}.\exp \left(-\frac{i}{\alpha . ite{r}_{\mathrm{max}}}\right), if\ {R}_2< ST\\ {}{X}_{i,j}+Q.L, if\ {R}_2\ge ST\end{array}} $$
(1)

Where t represents the current iteration, j = 1, 2, 3, ... d, itermax represents the maximum number of iterations, Xi,j represents the position information of the i-th sparrow in the j-th dimension, α∈[0,1] represents a random number, R2 ∈[0,1] represents the warning value, ST∈[0.5,1] represents the safety value, Q represents a random number following normal distribution, L represents a 1 × d matrix, and each element in the matrix is 1.

When the warning value is less than the security value, the discoverers can explore in a large range, and the range gradually decreases with the increase of iterations. When the warning value is bigger than the safety value, the discoverers detect the danger, and then the discoverers randomly go to other safe areas to search for food.

Entrants are the sparrows with the low energy in the population. The sparrows with lower energy are more difficult to find food in their area, so they have to fly to other areas or follow the discoverers to search for foods. Discoverers and entrants will replace each other with the amount of energy stored. The specific location update formula of the entrant is computed as follows:

$$ {X}_{i,j}^{t+1}=\Big\{{\displaystyle \begin{array}{c}Q.\exp \left(\frac{X_{worst}-{X}_{i,j}^t}{i^2}\right), if\ i>\frac{n}{2}\\ {}{X}_P^{t+1}+\mid {X}_{i,j}-{X}_P^{t+1}\mid .{A}^{+}.L, otherwise\end{array}} $$
(2)

Where XP is the best position of the current population, Xworst is the worst position of the current population, A is the 1 × d matrix, each element in the matrix is randomly 1 or − 1, and A+ = AT(AAT)−1. When i is greater than n/2, it means that it is very difficult for the sparrows with low energy to find foods, so they need to fly to other places to find foods, otherwise they will fly to the vicinity of the discoverers to get more energy.

In the sparrow population, some sparrows are called vigilant sparrows, which usually account for 10% - 20% of the total population. When they realize the danger, the sparrows near the edge of the group will quickly move towards the safest area to avoid the danger. While the sparrows at the optimal position of the population, it will randomly walk near other sparrows to avoid the danger. The specific vigilant sparrow’s position update formula is calculated as follows:

$$ {X}_{i,j}^{t+1}=\Big\{{\displaystyle \begin{array}{c}{X}_{best}^t+\beta .\mid {X}_{i,j}^t-{X}_{best}^t\mid, if{f}_i>{f}_g\\ {}{X}_{i,j}^t+K.\left(\frac{\mid {X}_{i,j}^t-{X}_{worst}^t\mid }{\left({f}_i-{f}_w\right)+\upvarepsilon}\right), if{f}_i={f}_g\end{array}} $$
(3)

Where Xbest is the optimal position of the current population, β is the step size, which is a normal distribution random number with mean value of 0 and variance of 1, K∈[−1,1], it represents a random number, fi represents the fitness of the current sparrow, fg represents the fitness of the current best sparrow, fw represents the fitness of the current worst sparrow, and ε is a small constant to prevent the denominator from being 0.

If the fitness of the current sparrow is greater than the best sparrow, which means that the sparrow is at the edge of the population and is vulnerable to attack, so it needs to move to the most secure central area. If the fitness of the current sparrow is equal to the best sparrow, which means that the sparrow is in the most secure area. At this time, it needs to move close to the nearby sparrows to avoid danger.

The algorithm flowchart is shown in Fig. 1.

  • Step 1 Initialize population and algorithm parameters.

  • Step 2 Calculate the fitness values and sort them from small to large, then divided the population into discoverers and entrants according to the proportion.

  • Step 3 Update the discoverers’ position via Eq.(1).

  • Step 4 Update the entrants’ position use via Eq.(2).

  • Step 5 Select some sparrows randomly from the population according to the proportion of vigilant sparrows, and use Eq.(3) to update the position.

  • Step 6 Recalculate the new position’s fitness. If the fitness is better than that of the previous iteration, update its position, otherwise give up.

  • Step 7 Judge whether the stop condition is satisfied. If it is satisfied, exit and output the best position. Otherwise, return to Step 2.

Fig. 1
figure 1

Flowchart of the SSA

2.2 Improved methods

According to the position updating formula Eq. (2), when the entrants move towards the optimal region, the direction is only 1 or − 1, which makes it easy to fall into the local optimal solution in the late iteration, and the population diversity is poor. Therefore, a new position updating formula is obtained by Eq. (4) with a nonlinear inertia weight of cosine function.

$$ {X}_{i,j}^{t+1}=\Big\{{\displaystyle \begin{array}{c}Q.\exp \left(\frac{X_{worst}-{X}_{i,j}^t}{i^2}\right), if\ i>n/2\\ {}{X}_P^{t+1}+w.\mid {X}_{i,j}-{X}_p^{t+1}\mid .{A}^{+}.L, otherwise\end{array}} $$
(4)
$$ w={w}_{\mathrm{max}}-\left({w}_{\mathrm{max}}-{w}_{\mathrm{min}}\right)\cos \left(\frac{\pi \cdot T}{G}\right) $$
(5)

Where w is the inertia weight, wmax and wmin are the maximum and minimum values of the weight, T is the number of current iterations, G is the maximum number of iterations. By introducing the nonlinear inertia weight of the cosine function, it can make the entrants explore more carefully and accurately near the current optimal position to make the local exploration ability stronger.

Levy flight was proposed by French mathematician Paul Levy in the 1930s. It is a probability distribution, a random step size that obeys Levy distribution. It is also a walking mode that can transform between a large number of short-distance search and occasional long-distance search. Mantegna algorithm is usually used to simulate, and the specific formula is as follows:

$$ u\sim N\left(0,{\delta}_u^2\right) $$
(6)
$$ v\sim N\left(0,{\delta}_v^2\right) $$
(7)
$$ {\delta}_u={\left\{\frac{\Gamma \left(1+\beta \right)\sin \left(\frac{\pi \beta}{2}\right)}{\Gamma \left(\frac{\left(1+\beta \right)}{2}\beta \times {2}^{\frac{\left(\beta -1\right)}{2}}\right)}\right\}}^{\frac{1}{\beta }} $$
(8)
$$ {\delta}_v=1 $$
(9)
$$ Levy=\frac{\delta_u\times u}{{\left|v\right|}^{\frac{1}{\beta }}} $$
(10)
$$ {X}_{i,j}^{t+1}=\Big\{{\displaystyle \begin{array}{c}{X}_{best}^t+ Levy.\mid {X}_{i,j}^t-{X}_{best}^t\mid, if{f}_i>{f}_g\\ {}{X}_{i,j}^t+K.\left(\frac{\mid {X}_{i,j}^t-{X}_{worst}^t\mid }{\left({f}_i-{f}_w\right)+\upvarepsilon}\right), if{f}_i={f}_g\end{array}} $$
(11)

Where u and v are random numbers of normal distribution, Levy is step size random number of Levy distribution, β is a constant, usually 1.5.

According to the vigilant sparrow’s position update formula, if the current sparrow’s fitness is not optimal, it will move towards the optimal position. The step size control parameter β is a random number of normal distribution with mean value of 0 and variance of 1, which is easy to make the algorithm fall into the local optimal solution in the late iteration. Therefore, the Levy flight random number is introduced to replace β, it will make the algorithm easy to jump out of the local optimal solution, improve the local exploration ability, population diversity, and the optimization performance of the algorithm.

3 Convergence analysis

3.1 Convergence criteria

The ISSA belongs to random search algorithm. Therefore, this paper determines the convergence behavior of ISSA through the convergence criterion of random algorithm [54, 55]. For the optimization problem, there are the random optimization algorithm D, the result of the k-th iteration Xk, and the result of the next iteration Xk + 1 = D(Xk, ζ), ζ is the searched solution in the iteration of the algorithm D.

The infimum of the search is defined as follows:

$$ \varphi =\operatorname{inf}\left(t:V\left[x\in A|f(x)<t\right]>0\right) $$
(12)

Where V(x) is the Lebesgue measure on the set x, A is the feasible solution space, f(x) is the fitness function.

The optimal solution region can be defined as follows:

$$ {R}_{\upvarepsilon M}=\Big\{{\displaystyle \begin{array}{c}\left\{x\in A|f(x)<\upvarphi +\upvarepsilon \right\}\Big\},\upvarphi\ \mathrm{is}\ \mathrm{limited}\\ {}\left\{x\in A|f(x)<-C\right\},\upvarphi =-\infty \end{array}} $$
(13)

Where ε > 0, C is a sufficiently large positive number. If algorithm D finds a point in the optimal solution region, then the algorithm finds an acceptable global optimal solution.

  • Condition 1: f (D (x, ζ)) ≤ f (x), if ζ∈A, then f (D (x, ζ)) ≤ f (ζ).

  • Condition 2: for BA, s.t. V(B) > 0, there is \( \prod \limits_{k=0}^{\infty}\left(1-{u}_k(B)\right)=0 \), where is the probability measure of the k-th iterative search solution of algorithm D on set B.

Let f be measurable, measurable space A be a subset of upper measurable, and algorithm D satisfy condition 1 and condition 2, \( {\left\{{X}_{\mathrm{k}}\right\}}_{k=0}^{\infty } \) is the sequence generated by algorithm D. Then probability measure\( \underset{k\to \infty }{\lim }P\left({x}_k\in {R}_{\upvarepsilon, \mathrm{M}}\right)=1 \), Rε, Mis the optimal solution region, and D is the global convergence.

3.2 Convergence analysis of ISSA

The position states of all sparrows in the population constitute the sparrow state, which can be recorded as s = (x1, x2,.... xN), where xi is the position state of the i-th sparrow, N is the number of sparrow population, and all possible states in the sparrow population constitute a state space, which can be recorded as S = {s = (x1, x2,... xN) | xiA, 1 ≤ i ≤ N}, and A is the feasible solution state space.

In the ISSA, the transition probability of sparrow position state from xi to xj is P (T(xi= xj), while the transition probability of sparrow population state from si to sj can be expressed as follows:

$$ P\left(T\left({s}_i\right)={s}_j\right)=\prod \limits_{k=1}^NP\left(T\left({x}_{ik}\right)={x}_{jk}\right) $$
(14)

From the above formula, we can know that the transition probability is obtained by multiplying the transition probability of each sparrow, so if s(t)∈S, then s(t + 1)∈S. The transition probability P (T(x(t)) = x(t + 1)) of each sparrow is only related to the state x(t), the number of sparrows i, the maximum iteration number itermax, the optimal sparrow position xp, the worst sparrow position xworst, and the random number Q at time t, but not related to time t. It can be concluded that the sparrow population position sequence s(t) generated by ISSA has Markov property and homogeneity, and the sparrow population state space s is a finite space. So ISSA’s sparrow population sequence {s(t), t ≥ 0} constitutes a finite homogeneous Markov chain.

In the ISSA, after each iteration, if the fitness value of a new position is better than the current best position, the new position will replace it and become the current best position. The best position of the algorithm is constantly changing and getting better in the iterative process. Therefore, the ISSA satisfies condition 1 of the convergence criterion.

If the optimal solution is x*, then the optimal state set of sparrow population is G = {s = {x} | f (x= f (x *), sS}, and GS. for any optimal state set si and non optimal state set sj, the transition probability from si to sj is as follows:

$$ P\left(T\left({s}_i\right)={s}_j\right)=\prod \limits_{k=1}^NP\left(T\left({x}_{ik}\right)={x}_{jk}\right) $$
(15)

In the optimal state set G, if at least one state reaches the optimal x*, then there is a transition probability P (T (x*= xjk) = 0, then P (T (si= sj) = 0, then we can conclude that the optimal state set G of sparrow population is a closed set on the state space S.

Suppose that there is a nonempty closed set M in the state space S, and M ∩ G = ∅, then for the state si = (x*) in G and the state sj = (xjk) in M, we can get f (x*) < f (xjk), and the transition probability of state sj to si can be known to be greater than 0, so M is not a closed set, so the hypothesis is not true. That is, there is only one closed set in the sparrow population state space S, which is the optimal state set G. That is, the Markov chain of the sparrow population state is irreducible.

Moreover, if there is a nonempty closed set E and there is no other nonempty closed set O to makeE ∩ O = ∅, So when j ∈ E, \( \underset{k\to \infty }{\lim }P\left({x}_k=j\right)={\pi}_j \), when j ∉ E, \( \underset{k\to \infty }{\lim }p\left({x}_k=j\right)=0 \), it can be concluded that when the iteration number of the ISSA tends to infinity, the sparrow population state must enter the optimal state set G, the probability that the ISSA can not find the global optimal solution is 0, so the condition 2 of convergence criterion is satisfied, it can be concluded that the ISSA is a global convergence algorithm.

4 Threshold image segmentation

Maximum entropy method was proposed by Kapur in 1985. The threshold selection standard of maximum entropy method is to maximize the total entropy of the segmented target and background (the largest amount of information).

Compared with the 2-D segmentation method, the 1-D segmentation method only considers the gray information of each pixel in the image, so the segmentation speed is faster. In 2-D methods, not only the gray information of each pixel, but also the gray information of its neighborhood is considered. The threshold t and region threshold s are selected to segment the image into four parts. The target and background (A and B in Fig. 2) are mainly concentrated in the two regions near the diagonal, and the other two regions are mainly the image edge and noise interference, we should makes full use of the gray information of the target and background areas, and more efficient and accurate to find the best threshold (t, s). Although the processing time of this 2-D method is long, the segmentation quality is better and the anti noise ability is superior.

Fig. 2
figure 2

2-D histogram

Here we take a pixel and its surrounding 3 × 3 area as a calculation area to calculate the regional gray mean value of a pixel:

$$ {p}_{ij}=\frac{n_{ij}}{M\times N} $$
(16)
$$ {w}_0\left(t,s\right)=\sum \limits_{i=0}^{t-1}\sum \limits_{j=0}^{s-1}{p}_{ij} $$
(17)
$$ {w}_b\left(t,s\right)=\sum \limits_{i=t}^{L-1}\sum \limits_{j=s}^{L-1}{p}_{ij} $$
(18)

Where Pij is the probability when the current pixel gray level is i and its field gray level average is j, nij is the number of pixels whose gray level value is i and field gray level value is j, M × N is the pixel size of the image, w0 and wb are the probability sum of target class and background class respectively, L is the gray level, L = 256.

The image edge and noise interference area information is little and the probability is very small. Thus, we only consider the diagonal target area and background area and set the following formula:

$$ {w}_b\left(t,s\right)=1-{w}_o\left(t,s\right) $$
(19)

For the threshold (t, s), the entropy expressions of target class and background class are described as follows:

$$ {H}_0\left(t,s\right)=-\sum \limits_{i=0}^{t-1}\sum \limits_{j=0}^{s-1}\frac{p_{ij}}{w_0\left(t,s\right)}\ln \frac{p_{ij}}{w_0\left(t,s\right)} $$
(20)
$$ {H}_b\left(t,s\right)=-\sum \limits_{i=t}^{L-1}\sum \limits_{j=s}^{L-1}\frac{p_{ij}}{w_b\left(t,s\right)}\ln \frac{p_{ij}}{w_b\left(t,s\right)} $$
(21)

2-D maximum entropy is calculated using Eq. (22).

$$ H\left(t,s\right)={H}_0\left(t,s\right)+{H}_b\left(t,s\right) $$
(22)

The best threshold is determined as follows:

$$ \left(t\ast, s\ast \right)=\mathrm{argmax}\left(0\le t\le L-1,0\le s\le L-1\right)\left\{H\left(t,s\right)\right\} $$
(23)

In the 2-D maximum entropy threshold image segmentation, the ISSA is used to find the best threshold:

$$ fun\left\{t\ast, s\ast \right\}=\arg \max \left(0\le t\le L-1,0\le s\le L-1\right)\left\{H\left(t,s\right)\right\} $$
(24)

In the ISSA, the lower the fitness, the better it is, so - fun {t, s} is taken as the fitness function.

The specific segmentation flowchart is shown in Fig. 3, and steps are explained as follows:

  • Step 1 Read the image to be segmented.

  • Step 2 Read the gray histogram of the image.

  • Step 3 Initialize the population and parameters.

  • Step 4 Calculate the fitness of all sparrows according to the Eq. (22).

  • Step 5 Implement the ISSA.

  • Step 6 Judge whether the stop condition is satisfied. If it is satisfied, exit and output the best threshold. Otherwise, return to Step 4.

  • Step 7 Use the best threshold {t *, s *} to segment the image and output the segmented image.

Fig. 3
figure 3

Image segmentation based on ISSA

5 Tests and analysis

5.1 Benchmark test

In order to verify the convergence and robustness of the ISSA, fifteen benchmark functions are used to test ISSA and other optimization algorithms such as PSO [29], ABC [20], FOA [18], GWO [44], CSO [49] and WOA [36]. The parameters of these algorithms are shown in Table 2 and the benchmark functions are listed in Table 3. The experiments were performed on the platform of MATLAB R2018a, using a Dell Laptop with an Intel Core i5 processor and 8 GB memory, running the Windows 10 operating system. The number of population is 50 and the iterations is 300, and each algorithm runs 30 times independently.

Table 2 Algorithm parameters
Table 3 Test functions

Table 4 shows the statistical results, it can be seen from Table 4 that for single-mode test functions F1-F5, the average value, best value and variance of ISSA are smaller than other algorithms, and the global optimal value can be found accurately. For multi-mode test functions F6-F10, other algorithms are easy to fall into the local optimal value, but ISSA can accurately find the global optimal solution, which fully reflects excellent optimization ability of ISSA algorithm. For multi-mode test function with fixed dimension F11-F15, most algorithms can accurately find the global optimal solution, but the variance of ISSA is the smallest, which fully reflects excellent robustness of ISSA algorithm.

Table 4 Test results

In order to further verify the convergence speed and accuracy of ISSA, the convergence curves of different algorithms are demonstrated in Fig. 4. For the convenience of observation, the ordinate of partial convergence curve is in the form of log.

Fig. 4
figure 4figure 4figure 4

Convergence curves. a F1 convergence curve b F2 convergence curve c F3 convergence curve d F4 convergence curve e F5 convergence curve f F6 convergence curve g F7 convergence curve h F8 convergence curve i F9 convergence curve j F10 convergence curve k F11 convergence curve l F12 convergence curve m F13 convergence curve n F14 convergence curve o F15 convergence curve

It can be seen from Fig. 4 that, for single-mode test function F1-F5, the convergence of ISSA is obviously better than other algorithms, and the accuracy is higher, especially in the middle and late iteration of ISSA algorithm. For multi-mode test functions F6-F10, the convergence performance of ISSA is still better, especially for the F7 test function. The convergence speed of ISSA is obviously faster than other algorithms in the early iteration. In the F10 test function, although the convergence speed of ISSA is not the fastest in the early and middle stages, the convergence accuracy in the later stage is better than other algorithms. For multi-mode test function with fixed dimension F11-F15, although there is little difference in the convergence of each algorithm, and they all converge to the optimal value in the early stage, the convergence speed of ISSA is slightly faster than other algorithms.

In the complexity test of the algorithm, five single-mode functions with the optimal value of 0 were selected for test. Within 2000 iterations, we recorded the number of iterations and running time when error of the best fitness value is less than 10−5. If the algorithm did not find a solution less than 10−5 within 2000 iterations, we recorded the running time of 2000 iterations.

From Table 5, we can see that ISSA can converge below 10−5 with the least number of iterations on the five test functions, and in general, ISSA has lower computation complexity, except F2. It can be concluded that under the same number of iterations, ISSA will spend a longer running time, but it makes up for this drawback with an excellent optimization ability.

Table 5 Complexity test results

From the above test results, we can draw a conclusion that the convergence speed, convergence accuracy and robustness of ISSA algorithm are superior to other seven algorithms, and it has better optimization ability.

5.2 Application to threshold image segmentation

In this section, the ISSA is applied to threshold image segmentation, the optimal threshold and image segmentation quality are compared with image segmentation results based on GEO [38], RSO [8], TSO [46], CRSSA [35], MSCA [48], HHO-PCNN [14], 2D-OTSU method [31] and 1D-Exponential entropy method [43]. The maximum number of iterations is 30, the population size is 20. The parameters to be set for algorithms are shown in Table 6.

Table 6 Parameters of the partial algorithms

5.2.1 Application to classical images

We selected three gray images, six color images and three images with different noises for experiments. The test images and their resolutions and gray histograms are shown in Fig. 5.

Fig. 5
figure 5figure 5figure 5

The test images and corresponding histograms. a Lena(512 × 512) b Boat(720 × 576) c Zelda(512 × 512) d Aircraft(512 × 512) e Monkey(500 × 480) f Flower(512 × 480) g Butterfly(768 × 512) h Parrot(768 × 512) i Bear(394 × 600) j Gaussian noise(512 × 512) k Salt pepper noise(512 × 480) l Poisson noise(768 × 512)

From the results in Table 7, we can see that the proposed method is obviously superior to other methods. In twelve images, the threshold values sought by eleven images have higher entropies, which reflects the good convergence and high robustness of the ISSA-based segmentation method. Although MSCA-based segmentation method has also obtained a good threshold, on the whole, the performance of the ISSA-based segmentation method is more prominent.

Table 7 Comparison of the threshold and 2-D maximum entropy by different algorithm

Tables 8 and 9 show the PSNR and FSIM of the nine methods for twelve images. It can be seen that the threshold obtained by ISSA is used for image segmentation, although the PSNR and FSIM of some images are not ideal, the overall performance of ISSA-based segmentation is better. The segmented images are shown in Fig. 6.

Table 8 Comparison of the PSNR
Table 9 Comparison of the FSIM
Fig. 6
figure 6figure 6

Segmented images. a Lena b Boat c Zelda d Aircraft e Monkey f Flower g Butterfly h Parrot i Bear j Gaussian noise k Salt pepper noise l Poisson noise

5.2.2 Application to medical images

The outbreak of COVID-19 has brought great harm to people all over the world, and countless people have lost their lives. Image segmentation is also widely used in the medical field. For medical images, how to segment accurately is particularly important [3]. For lung CT images, the primary task of image segmentation is to segment the lung organs and nodules in the lung, which can enable doctors to judge the situation of the lung more accurately and prevent wrong judgment caused by blurred images [2]. Therefore, we used five lung CT images of COVID-19 patients to verify the effectiveness of the proposed method. The CT images, as well as the corresponding resolution and gray histogram are shown in Fig. 7 [2].

Fig. 7
figure 7figure 7

Lung CT images and corresponding histograms. a Lung 1(725 × 551) b Lung 2(570 × 436) c Lung 3(563 × 437) d Lung 4(556 × 398) e Lung 5(457 × 285)

Tables 10, 11, 12 show a comparison of the thresholds, optimal entropy, PSNR and FSIM of different methods for five lung images. It is noted from the tables that other algorithms can find the threshold corresponding to the maximum entropy, but the effect of segmentation using these obtained threshold is not very ideal. Since ISSA can not only find the threshold of maximum entropy, but also the segmented images based on the found threshold have larger PSNR and FSIM.

Table 10 Comparison of the threshold and 2-D maximum entropy
Table 11 Comparison of the PSNR
Table 12 Comparison of the FSIM

Figure 8 shows the segmented images obtained by ISSA method. It can be seen from Fig. 8 that the lung organs are completely segmented, and the nodules and diseased tissues in the lung are clearly distinguished, which plays a certain role in the diagnosis of COVID-19 patients.

Fig. 8
figure 8

Lung CT segmentation images. a Lung 1 b Lung 2 c Lung 3 d Lung 4 e Lung 5

6 Conclusion

This paper proposes an ISSA by combining the nonlinear inertia weight and Levy flight and applies the ISSA to threshold image segmentation based on 2-D maximum entropy. The experimental results deliver several conclusions. First, compared with other algorithms, ISSA has faster convergence speed, more accurate convergence results and stronger robustness. Second, Through the threshold obtained by ISSA optimization for classical images segmentation, the maximum entropy is obtained, and higher PSNR and FSIM are achieved. The quality of segmented images is better. Third, the segmentation results for lung CT images show that in medical application, ISSA can still obtain better performance, including higher PSNR and FSIM. The nodules and diseased tissues on lung organs can be clearly segmented.

Tables 13 and 14 list algorithms that obtained the highest PSNR and FSIM in experiments, and record number of times to obtain the optimal values when segmented different images. The statistical results show the ISSA performs better in image segmentation of different types of images. Since in most tests, PSNR and FSIM obtained using ISSA method are the best.

Table 13 Number of times to get the highest PSNR
Table 14 Number of times to get the highest FSIM

The experiment results confirm the effectiveness of the proposed method, but there are some drawbacks. The running time of the ISSA increases compared with SSA, and in test function F7, ISSA cannot converge to the global optimal 0.

Image segmentation remains one of the main issues in image processing, this study deserves further methodological, algorithmic and numerical investigations. And as a newly proposed swarm intelligence optimization algorithm, the SSA has strong robustness, fast convergence speed, and can be applied to optimization problems in other areas, so it has great research significance. In future work, we will continue to focus on improvement of swarm intelligence optimization algorithm, and combine with deep learning method to solve image processing problems.