## 2 Materials and Methods
### Dataset Creation and Preparation  
This retrospective study was approved by the Ethics Committee of Hospital Garcia de Orta, and the requirement for informed consent was waived as all data included in this study were anonymized beforehand. All the MRI studies, acquired in that institution  
Figure 1: Overview of the methodology applied in the study, illustrating the machine learning pipeline for adrenal lesion detection and classification, including MRI dataset preparation, lesion detection, and binary classification of adenomas versus non-adenomas. between 2008 and 2019, were pre-analyzed by radiologists during routine clinical practice, with medical reports already available for each study. For this research, a medical expert reviewed the MRI studies and annotated the adrenal lesions by adding bounding boxes to the images. Only one study was selected for each patient based on its overall quality. All the selected studies had at least axial and coronal T2W, T1W CS, and T1W contrast-enhanced (CE) sequences and the presence of at least one adrenal lesion. Table 1 provides an overview of the dataset. The original dataset was balanced in terms of the patient's gender but showed an imbalance in the types of adrenal lesions, with adenomas being much more prevalent than other lesions. The lesion dimensions also had limited variability. Additional processing was required to create the final dataset that was used to train and test the ML models. Each DICOM study was exported from the hospital's system and converted to an image dataset, with the labels stored using Fiftyone [48] toolkit and CVAT ([[https://www.cvat.ai/](https://www.cvat.ai/)]([https://www.cvat.ai/](https://www.cvat.ai/)) (accessed in 26 January 2025)) annotation tool. The PyDicom package ([[https://github.com/pydicom/pydicom](https://github.com/pydicom/pydicom)]([https://github.com/pydicom/pydicom](https://github.com/pydicom/pydicom)) (accessed in 29 January 2025)) was employed to extract relevant metadata from the DICOM studies and to convert the DICOM files into 512 \(\times\) 512 PNG images, which was the default size of the slices. Similarly to most studies on adrenal lesions, our final dataset consisted exclusively of axial slices, which is \begin{table}
\begin{tabular}{l l} \hline \hline
**Attributes** & **Values** \\ \hline
**Original Dataset** & \\
**Number of Patients** & 215 \\ Female & 105 \\ Male & 104 \\ Undefined & 6 \\ \hline
**Median Age (years)** & 67 \\ \hline
**Number of Lesions** & 243 \\
**Lesion Dimensions (mm)** & \\ Max & 110.0 \\ Min & 10.0 \\ Mean & 23.35 \\ Standard Deviation & 11.68 \\ \hline
**Lesion Type (\% of Total Lesions)** & \\ Adenoma & 83.72\% \\ Metastasis & 11.63\% \\ Pheochromocytoma & 2.79\% \\ Myelolipoma & 1.40\% \\ Lymphoma & 0.47\% \\ \hline
**Final Dataset** & \\
**Number of Images** & 12,593 \\ Lesion Images & 6171 \\ Adenoma Images & 4695 \\ Non-Adenoma Images & 1476 \\ Non-Lesion Images & 6422 \\ \hline \hline \end{tabular} Note: Bold text indicates category headers used to group related attributes. Row color is used to highlight the original and final datasets.  
\end{table} 
Table 1: Dataset description. Summary of the original and final dataset characteristics. the standard imaging orientation for evaluating these lesions. To create a dataset to train a lesion detection model, 12,593 slices were selected using an automated \"window-based selection\" approach, to address the imbalance between the lesion and non-lesion slices. For each group of lesion slices in the MRI studies (most lesions spanned multiple consecutive slices), we included three slices before and three slices after the lesion group, with two slices of interval. We used this interval to avoid slices with small portions of lesion--that were not labeled as lesion slices due to potential annotation inaccuracies--to be considered as non-lesion slices. Table 2 shows a graphical explanation of the slice inclusion algorithm.