# Using an Artificial _Physarum polycephalum_ Colony for Threshold Image Segmentation
## 4 Algorithm Steps of APPCA
### Step 2: Expansion
```
1:Input: the original image, \(H\), \(V\), grayscale \(L\)
2:Define: the fitness function in Equation (5)
3:Initialization: the APPC, \(M\), \(S\), \(p_{s}\), \(p_{f}\)
4:Calculate: randomly generate hyphae \(\left\{x^{k}(1)\right\}\)
5:Initialization: \(T_{max}\), \(Ite\_max\), \(e_{th}\)
6:For \(Ite=1\):\(Ite\_max\)
7:For hyphae \(k=1:S\)
8:Random select a pixel
9:Self-learning
10:Social learning by \(p_{s}\)
11:Free learning by \(p_{f}\)
12:To integrate the three parts of the expansion population
13:To update the _Physarum polycephalum_ colony by Equation (18)
14:End for
15:To update the _Physarum polycephalum_ colony by Equation (19)
16:Return the solutions to threshold image segmentation
17://contraction algorithm
18:End for
19://Output the optimal segmented image
```
**Algorithm 2** Expansion with a dual-loop

Compared with the expansion algorithm with a triple-loop in Algorithm 1, the improved expansion algorithm in Algorithm 2 has a dual-loop, so the time complexity of the expansion algorithm is improved as \(O(Ite\_maxSHV)\), and the space complexity is enhanced to \(O(SHV)\). In the dual-loop of expansion, the APPC uses a total of \(S\) hyphae to search for a total of available \(HV\) pixels and selects the optimal solutions to the same threshold image segmentation. After improvement, the new algorithm no longer distinguishes the source of hyphae, and the time and spatial performance have been greatly improved. The improved APPC expansion algorithm both has good search capabilities and higher computational efficiency. ### Step 3: Contraction

In this step, the artificial _Physarum polycephalum_ colony will contract and the optimal solutions to the threshold image segmentation will be selected. The population size of the Physarum hyphae will decrease after comparing the fitness of the feasible solutions. As we all know, the population size increases from \(S\) during initialization to \((2+p)S\) after expansion, but not all hyphae can survive. Only the hyphae with the highest fitness of population size \(S\) can survive after contraction, the other population \((1+p)S\) with low fitness will disappear. There is

\[x^{*}(Ite)=\Big{\{}x^{k*}(Ite)\Big{|}fitness\Big{(}x^{k*}(Ite)\Big{)}\geq\ fitness \Big{(}x^{l}(Ite)\Big{)},k<S,l>S\Big{\}}. \tag{20}\]

The _Physarum polycephalum_ colony will compare the fitness obtained by Equation (5), and the optimal hyphae \(x^{1*}(Ite)\) with the highest fitness will be selected as the optimal scheduling solution to be output. \[fitness\Big{(}x^{1*}(Ite)\Big{)}\ \geq fitness\Big{(}x^{k*}(Ite)\Big{|}k=1,2,3, \ldots,S\Big{)} \tag{21}\]

Similarly, here also consider two cases, i.e., contraction with a triple-loop and contraction with a dual-loop. Assuming the scale of the threshold image segmentation includes a total of available \(HV\) pixels, and the population size of the _Physarum polycephalum_ colony algorithm includes the maximum number \(M\) of _Physarum polycephalum_ and the maximum number \(S\) of hyphae. Bubble sort is employed to rank the fitness of hyphae with a population size (2+\(p\))\(MS\) in total. The pseudo-code of contraction is shown in Algorithm 3.