# YOLO-OHFD: A YOLO-Based Oriented Hair Follicle Detection Method for Robotic Hair Transplantation
## 2 Materials and Methods
### Structure of YOLO-OHFD
#### 2.2.3 Feature Detection Network Based on Decoupled Heads  
Decoupled heads are employed to predict the position, angle, and classification of oriented hair follicles. Additionally, angle smoothing algorithms and densely encoded labels are integrated into the angle classification prediction to supplant the conventional angle regression approach.  
Currently, the prevalent methods for defining Oriented Bounding Boxes (OBBs) include the five-parameter and eight-parameter methods. Figure 6 illustrates these common approaches. The five-parameter method, characterized by fewer parameters and reduced computational complexity, is more apt for this study. Nonetheless, the interchangeability of edges in the OpenCV definition method can lead to irregular loss calculations. Consequently, we have chosen to utilize the long edge definition method to represent the OBB, which provides a more stable and accurate framework for our analysis [33].  
Figure 5: Structure of feature fusion network based on FAM. (**a**) Neck is the feature fusion network named FPN. (**b**) Structure of FAM based on DCN.  
The parameters of the OBB are predicted, which has worked well in many rotation detection tasks. However, there is a boundary discontinuity problem during angular regression prediction. It results in large loss values, and some targets may be misdiagnosed and missed due to their proximity to the angular boundary.  
Therefore, we solve the above problem by transforming angle prediction from a regression problem to a classification problem. First, the angle of hair is classified in its category; 180 categories are defined in this article. Then, circular smooth label (CSL) is proposed to ensure the continuity between predicted angles [34]. The structure of CSL is shown in Figure 7. Then, the loss value between the predicted label and ground truth is calculated by (3).  
\[CSL(x)=\begin{cases}g(x),q-r<x<q+r\\ 0\ \,\ \ \ \ \ \ otherwise\end{cases} \tag{3}\]  
where \(\theta\) is the angle of the oriented box. \(\mathrm{g(x)}\) is a Gaussian function as a window function. r is the radius of the window function.  
However, the classification for 180 categories leads to too thick a prediction layer, and a huge number of parameters reduce the operation efficiency. Therefore, the Gray-coded label (GCL) is proposed to reconstruct the prediction layer, which greatly reduces the parameters of the prediction layer without affecting the angular prediction error [35].  
In addition, in order to solve the coupling problem between hair follicle position, angle, and classification, we design a decoupled head with the structure shown in Figure 8. The decoupled head distributes the regression and classification tasks through parallel convolutional layers, which can better apply the feature information focused on by different tasks for prediction, in order to further improve the accuracy of detection.  
Figure 6: OBB definition methods. (**a**) OpenCV definition method: \(\{\mathrm{x},\mathrm{y},\mathrm{h},\mathrm{w},\theta\in[-90,0)\}\). (**b**) Long edge definition method: \(\{\mathrm{x},\mathrm{y},\mathrm{h},\mathrm{w},\theta\in[-90,90)\}\). (**c**) Ordered quadrilateral definition method: \(\{\mathrm{x}_{1},\mathrm{y}_{1},\mathrm{x}_{2},\mathrm{y}_{2},\mathrm{x}_{3},\mathrm{y}_{3},\mathrm{x}_{4},\mathrm{y}_{4}\}\).  
Figure 7: Circular smooth label.