## 3 Methods
### Recognition of Synapse
#### 3.2.2 Rectifying Detection Results of Synapses on the Serial EM Image Stack  
Confirming the connection of objects on serial images in 3D is helpful in rectifying the detection results [28]. We present an algorithm for confirming the connection of synapses in 3D. We denote by \(P_{i,j}\) the \(j^{\text{th}}\) synapse on the \(i^{\text{th}}\) section, in which the index \(j\) is randomly given. The algorithm includes the following steps:  
1. For the synapse on the first section \(P_{1,j}\), we assign it a 3D serial number \(N_{1,j}^{3d}=j\). Figure 4: The raw image and image processed with histogram equalization. (**A**) Left: raw image; middle: zoomed area containing an MSB; right: histogram of the raw image; (**B**) left: image processed with histogram equalization; middle: zoomed area containing an MSB; right: histogram of the image processed with histogram equalization. For the synapse on the \(i^{\text{th}}\) section \(P_{i,j}\), \((i>2)\), we calculate the Euclidean distance between \(P_{i,j}\) and \(\{P_{\bar{r}}\}_{i^{\prime}=i-3}^{i-1}\). Denote by \(\mathcal{D}_{j,\bar{r}}^{i,\bar{r}}\) the distance between \(P_{i,j}\) and \(P_{\bar{r},\bar{r}}\): \[\mathcal{D}_{j,\bar{r}}^{i,\bar{r}}=\|c_{i,j}-c_{i^{\prime},\bar{r}}\|_{2},\] (3) where \(c_{i,j}\) is the centroid of the bounding box of \(P_{i,j}\). 3. Find the closest synapse to \(P_{i,j}\), and denote it by \(P_{i^{\prime\prime},\bar{r}^{\prime\prime}}\). \[\underset{i^{\prime\prime},\bar{r}^{\prime\prime}}{\text{argmin}}\{\mathcal{D }_{j,1}^{i,j-1},\mathcal{D}_{j,2}^{i,j-1},\cdots,\mathcal{D}_{j,1}^{i,j-3}, \mathcal{D}_{j,2}^{i,j-3},\cdots\}.\] (4)
4. Verify if \(P_{i,j}\) is the closest synapse to \(P_{i^{\prime\prime},\bar{r}^{\prime\prime}}\) on the \(i^{\text{th}}\) section. Find the closest synapse to \(P_{i^{\prime\prime},\bar{r}^{\prime\prime}}\) on the \(i^{\text{th}}\) section, and denote it by \(P_{i,j^{\prime\prime}}\). \[\underset{i,j^{\prime\prime\prime}}{\text{argmin}}\{\mathcal{D}_{j^{\prime \prime},1}^{i^{\prime\prime},1},\mathcal{D}_{j^{\prime\prime},2}^{i^{\prime \prime},i},\cdots\}.\] (5) If \(j^{\prime\prime\prime}=j\) and the distance between \(P_{i,j}\) and \(P_{i^{\prime\prime},\bar{r}^{\prime\prime}}\) is smaller than a given threshold \(\theta\) (according to the thickness of sections of 50 nm, i.e., 25 pixels in the x-y direction, we set \(\theta=100\)), \[\mathcal{D}_{j,\bar{r}^{\prime\prime}}^{i,\bar{r}^{\prime\prime}}\leq\theta,\] (6) we consider that \(P_{i,j}\) and \(P_{i^{\prime\prime},\bar{r}^{\prime\prime}}\) are the same synapse appearing on different sections. Then, we assign the 3D serial number of \(P_{i,j}\) to \(P_{i^{\prime\prime},\bar{r}^{\prime\prime}}\). If \(j^{\prime\prime\prime}\
eq j\) or Equation (6) is not satisfied, we consider that \(P_{i,j}\) and \(P_{i^{\prime\prime},\bar{r}^{\prime\prime}}\) are not the same synapse in the 3D perspective. We assign a new 3D serial number to \(P_{i^{\prime\prime},\bar{r}^{\prime\prime}}\). With the algorithm for assigning the 3D serial number to synapses on the serial image stack, we give each synapse on the serial image stack a 3D serial number. The same synapses appearing on different sections have the same 3D serial number. Based on this, it is easy to count the number of synapses in the 3D perspective. A synapse is a spatial structure with a size of about 200 nm [7]. Therefore, one synapse should appear on at least 3 adjacent sections under the condition that the thickness of the section is 50 nm. We deleted the synapses that appeared on less than 3 layers, which were considered as pseudo-synapses. Meanwhile, in order to avoid the inaccuracy of synapse statistics caused by synapses that were missed, as shown in Figure 6, where the yellow rectangle indicates missed, while the red rectangles indicate correct detection, we also needed to locate the synapses that were missed.