# Design and Validation of a U-Net-Based Algorithm for Star Sensor Image Segmentation
## 2 Materials and Methods
### Algorithm Design and Configuration  
In this section, our proposed AI-based algorithm's scheme is described and shown (Figure 4). It will be referred to it as the brightest objects sky segmentation (BOSS) algorithm.  
The monochromatic raw image from the camera arrives at the preprocessing module where it will be resized, normalized and vectorized into a floating point array. This module  
Figure 4: BOSS algorithm scheme: data are in orange, and modules are in light blue.  
Figure 3: Dataset samples: real night sky image (on the **left**) and relative mask (on the **right**).  
will be tailored according to specific sensors' bit depth, while the size must be the one the NN is trained on. Then, the array is processed by the trained U-Net which gives its output prediction. This is a 2D array where every pixel has an associated value of probability \(p\) of being foreground. If \(p\geq p_{min}\), then this value is rounded up to 1. After the thresholding filter, a binary image is obtained, and its element product with the original image will provide an array with just active pixels' energy values. This output will be used by the clustering algorithm to detect clusters and compute their centroids and total energies. The clustering module developed within this work takes all the active pixels in the segmented image and organizes them in a list. Then. it associates the first pixel in the list to the first cluster and starts to verify if the next pixels are part of the same cluster or not through a distance-based criterion. Whenever the next active pixel does not belong to the already identified clusters, then a new cluster is identified.  
The distance criterion uses the Euclidean norm and the condition to assess the membership of two active pixels (\(\mathbf{p}_{i}\) and \(\mathbf{p}_{j}\)) to the same cluster as expressed by Equation (1).  
\[\|\mathbf{p}_{i}-\mathbf{p}_{j}\|\leq\sqrt{2} \tag{1}\]  
The clustering algorithm then first performs a filtering action with a minimum and maximum dimension and then a sorting of all the clusters. A minimum dimension filter is needed to avoid a possible noise signal in the clustering outputs (ex. hot pixels), while the maximum dimension filter is needed to avoid great detected clusters due to non-stars objects.  
The sorting operation is then performed in descending order and considers the first N clusters in output from the previous filtering actions. It is based on a combination (Equation (2)) of the clusters' dimension (\(dim_{cluster}\)), energy (\(E_{cluster}\)) and maximum energy value (\(max(E(\mathbf{p}_{i}))\)) over the cluster because this sorting index proved to be suitable to select the best clusters for star pattern recognition purposes with the conducted tests.  
\[Sorting\;Index=\frac{E_{cluster}}{dim_{cluster}}\times max(E(\mathbf{p}_{i} ))\;\;with\;i\;over\;cluster \tag{2}\]  
N is computed by applying a 1.25 factor to the average number of stars which depends on the FOV and cut-off magnitude of the selected sensor [2]. The maximum number of clusters in output is fixed a priori to process just the most significant ones, and the 25% margin factor is selected to take into account possible uncertainties of the average number of stars formula.  
The U-Net is capable of resolving background and foreground pixels after training, validation and test phases, but it still gives continuous values that have to be discretized. This is the reason why the thresholding filter and the selection of a reasonable value for \(p_{min}\) will be described in the next sections in order to obtain the best correspondence between algorithm prediction and targeted masks. Once the U-Net is trained and \(p_{min}\) selected, the BOSS algorithm will be compared with traditional image segmentation ones, both described in the next section in terms of segmentation performance.