# Reconstructing Nerve Structures from Unorganized Points
## 4 Materials and Methods
### Finalizing the Individual Clusters and Forming the Final Contours  
The parameter \(S_{xy}\) from the formula (29), or the formula (7), is used as a criterion for finalizing the current cluster/graph. \(S_{xy}\) with a positive value indicates that the successor \(Y\) of the point \(X\) was found. A negative value of \(S_{xy}\) suggests that the found node does not have its successor, i.e., that the algorithm has reached the root of the graph. The situation where \(S_{xy}\) is zero represents a borderline case. In terms of the probability density function, this case would correspond to a \"flat\" local maximum, where more than one potential maximum value can be found.  
At the end of each iteration, which involves the analysis and incorporation of point(s) into the current cluster, the algorithm checks for any unsorted points remaining in the area \(G(Y)\) surrounding the cluster's last point (\(Y\)). If such points are detected, the previously described procedure is repeated, focusing on the point \(Y\) (as illustrated in Figure 8, and the accompanying pseudocode, which can be found in Appendix A). If the control does not return/find any potential candidates in the area \(G(Y)\), the current cluster is finalized. New clusters are formed as long as there are still some unsorted points left.  
Once all the clusters are formed, the algorithm checks which ones should be connected, in order to get the final nerve contours. For that purpose, around each cluster's terminal node \(X\) and its predecessor \(X_{p}\), an area in the form of a circle sector is made (as shown in Figure 9):  
\[\Xi(X)=\{Z:\left\|X-Z\right\|\leq r_{1},\angle(X-X_{p},Z-X)<\theta\}, \tag{31}\]  
where \(r_{1}\) and \(\theta\) are empirically derived values of the sector's radius and of one half of the sector's central angle, respectively. When some other cluster's terminal node \(Y\) belongs to \(\Xi(X)\), that cluster is considered to be an extension/continuation of the current cluster.  
Remarks: Two evaluations used before the final contours are formed will be reported in the following paragraphs.  
The initial evaluation indirectly assesses the dimensions of the selected area \(G(X)\). If, in post-cluster formation, there is a pronounced number of extremely small clusters (consisting of three points or fewer, determined empirically), as in example in Figure 10, the algorithm deduces that the chosen \(G(X)\) area was undersized. As a result, the entire process restarts with an expanded radius for \(G(X)\).  
In the second evaluation, clusters containing fewer than \(n\) points, where \(n\) was empirically set to 1 or 2 points, are considered for elimination. These smaller clusters, often located close to larger ones, typically do not significantly influence the final reconstruction, but can pose challenges during the final contour-formation stage.  
Figure 7: The NN approach used in our method. The search is performed in the sector of a circle (shaded area), where \(r_{1}\) is the radius and \(2\alpha\) is the central angle of the sector. The sector’s center is placed in the point \(X\), while its bisection passes through the point \(Y\). In this example, the resulting order of points in the graph would be: \(\{X,Y_{1},Y_{2},Y\}\).  
Figure 8: Flowchart with the algorithm steps. Each color represents a specific part of the algorithm: initialization of the algorithm and finalization of individual clusters (yellow), valley-seeking clustering and adaptive Kalman filter (blue), check for omitted points through NN classification (green), and steps for the formation of final contours (red). The flowchart complements the pseudocode provided in Appendix A, such that Ax.Ly in the flowchart relates to the \(y\)th line of the algorithm \(x\) in Appendix A.