# Automatic Segmentation of Histological Images of Mouse Brains
## 2 Materials and Methods
### Deep Learning Models  
Several deep learning models were tested. Initially, we chose to work and test these models at low resolution (512 \(\times\) 256) to verify their ability to capture important features in the mouse brain. The first tested model, U-Net, proposed by [PERSON] et al. [14], was used as a starting point to segment brain regions, since this architecture is considered as the method of reference in medical image segmentation. We chose to work with a depth of 5 levels and with feature maps in the encoder of 3, 16, 32, 64 and 128; and 256, 128, 64, 32 and 16 for the decoder, being the initial configuration of the architecture. Each experiment was trained for 100 epochs with a minibatch size of 32 images. An Adam optimization was performed and weights were saved for the epoch that produced the last train iteration. A starting learning rate was fixed at 0.01 with a scheduler function that reduces the learning rate by a factor of 10 after 15 consecutive epochs. An early stopping function was implemented to make the model training process time efficient. The model was trained with the Pytorch framework using a NVIDIA A100 GPU. Two different loss functions were tested, binary cross entropy with logits loss (BCE) and Dice loss. The Dice loss function was chosen because it offers better performance in the chosen evaluation metric (Dice Score Coefficient, DSC). Moreover, at the end of this round, using low definition images, it was concluded that the U-Net architecture was not able to acquire enough information to adequately delimit the regions of interest. Indeed, it \begin{table}
\begin{tabular}{l l l l l l} \hline
**GROUP 1** & \multicolumn{4}{c}{**GROUP 2**} \\ \hline
**Name** & **Tag** & **Name** & **Tag** & **Name** & **Tag** \\ \hline Inferor Colliculus & InfC & anterior commisure & aca & Hippocampus & HP \\ Superior Colliculus & SupC & corpus callosum & cc & Lateral Ventricle & LV \\ Intra Granular Layer & IGL & Cingulate cortex & Cg & optic chiasm & och \\ Total Cerebellum & TC & Caudate Putamen & CPUu & stria medularis & sm \\ Substancia Nigra & SN & Dentate Gyrus & DG & Total Cortical area & TCTX \\ Pontine nucleus & Pn & Dorsal Subiculum & DS & pyramidal cell layer & TILpy \\ fibers of the pons & fp & fornix & f & Thalamus & TTH \\ Total Brain & TB & fimbria & fi & Ventro Median Hypothalamus & VMHvl \\ \hline \end{tabular}
\end{table} 
Table 1: Neuroanatomical features. To train the deep learning model for images in group 1, the entire image was used as input. Meanwhile, for images in group 2, the total brain region was used as input. was necessary to apply extensive post-processing of the images to improve segmentation. This model was thus discarded from the next round of testing which used low (521 \(\times\) 256) and medium (2048 \(\times\) 1024) resolutions. The second tested model is based on the work of [PERSON] et al. (2015), who proposed a weakly supervised method using Attention U-Net for colon cancer image segmentation. The addition of attention blocks dynamically weighs the importance of different image regions during the segmentation process. This enables the network to focus on relevant features and enhances the accuracy of the segmentation results. Initially, the same depth and features map as the previous architecture were maintained. Figure 3 presents a visual comparison between both architectures. Given the promising segmentation results, we decided to use an encoder/decoder feature maps consisting of 3, 64, 128, 256 and 512; and 1024, 512, 256, 128 and 64, respectively. However, increasing the number of levels from 5 to 7 (encoder, 3, 64, 126, 256, 512, 1024, 2048 and decoder, 4096, 2048, 1024, 512, 256, 128, 64) gave better segmentation results while increasing the image resolution to 2048 \(\times\) 1024. In order to train and test the models, the database of all masks and images was divided into 3 groups. We used 70%, 15% and 15% for training, validation and testing, respectively.