# A Deep Learning Approach to Teeth Segmentation and Orientation from Panoramic X-Rays
## 3 Materials and Methods
### Oriented Bounding Box (OBB)  
To implement the oriented bounding box (OBB), we utilize principal component analysis (PCA) [18]. PCA is a statistical technique that transforms correlated observations into uncorrelated values called principal components. It ensures the first component captures the most variance, and subsequent components maximize variance while staying uncorrelated with preceding ones through orthogonal transformations.  
We chose PCA due to its interpretability, computational efficiency, and effectiveness in capturing the primary axis of orientation from segmented tooth regions. While deep  
Figure 6: Post-processing cases to refine segmentation outputs. The red regions represent unwanted fragments with the same label as a nearby tooth. Black dots indicate border pixels of these unwanted regions. Three typical scenarios are illustrated: (a) Case-I: unwanted region surrounded entirely by background, which is removed; (b) Case-II: unwanted region adjacent to background and a labeled tooth, which is merged with the label; (c) Case-III: unwanted region bordering multiple labeled teeth, which is merged with the most frequent adjacent label.  
learning-based or regression-based OBB predictors are potential alternatives, they typically require supervised training with ground truth orientation angles, which are not available in the DNS dataset. We selected PCA over minimum-area bounding rectangles (e.g., OpenCV's minAreaRect) because, unlike minAreaRect, which returns a rotated rectangle without clear directional cues, PCA explicitly identifies the dominant direction of the tooth contour, making it more suitable for estimating rotation in our context. The steps involved in generating OBBs in this paper are as follows:  
_Tooth separation_: We approach the OBB generation for each tooth individually. This involves keeping one tooth in the image while rendering the others as background. The image is then binarized.  
_PCA_: We then calculate the first two major principal components (PCs) and determine the angle between the first PC and the horizontal axis, which we refer to as _PCAangle_.  
_Rotation_: We then generate a 2D rotation matrix to rotate the tooth and align it vertically. The rotation matrix for rotating a point (\(x\), \(y\)) by an angle (\(\theta\)) around an arbitrary pivot (\(x_{c}\), \(y_{c}\)) can be expressed as follows:  
\[\begin{bmatrix}x\\ y\\ 1\end{bmatrix}=\begin{bmatrix}\cos\theta&-\sin\theta&x_{c}(1-\cos\theta)+y_{c} \sin\theta\\ \sin\theta&\cos\theta&y_{c}(1-\cos\theta)-x_{c}\sin\theta\\ 0&0&1\end{bmatrix}\begin{bmatrix}x\\ y\\ 1\end{bmatrix} \tag{1}\]  
We calculate \(\theta\) in the following way:  
\[\begin{cases}\theta=180+\left(90-PCA_{angle}\right)&if\ PCA_{angle}<0\\ \theta=\left(90-PCA_{angle}\right)&otherwise\end{cases} \tag{2}\]  
_HBB_: After aligning the tooth vertically, we proceed to plot the horizontal bounding box (HBB). Generating an HBB from contour points is much easier than generating an OBB.  
_Inverse rotation_: We then rotate the tooth along with the HBB back to its original position. To achieve this, we substitute \((-\theta)\) into Equation (1).