# CycleGAN-Driven MR-Based Pseudo-CT Synthesis for Knee Imaging Studies
## 2 Materials and Methods
### Cycle-Consistent Generative Adversarial Network
#### 2.2.3 Data Preprocessing and CycleGAN Training  
A first step dedicated to image preprocessing is essential to ensure the quality of the expected outcome. In this sense, intensity normalization and spatial standardization processes were implemented, including the following:  
* The _N4 ITK MRI Bias Correction_ algorithm was applied to reduce field inhomogeneities associated with interactions and imperfections of the employed radio frequency coils.  
Figure 2: CycleGAN overall architecture, showing the dual generative network structure components G and F synthesizing images from the MR to the CT domain, and vice versa, and the dual discriminative network structure components D and E, assessing the images synthesized by G and F.  
For this purpose, the implemented 3D Slicer module was used over T1-weighted MR images [33].
* MR and CT images were resampled to achieve an isotropic 1 mm space using the _Resample Scalar Volume_ module in 3D Slicer. This step was crucial in establishing a consistent 1 mm isotropic resolution across all images.
* Intra-patient registration aimed at aligning each MR-CT pair. The process included several steps: initially, manual registration was performed to ensure the same spatial localization of the images, using the _Transforms_ module in 3D Slicer. This was followed by an automatic elastic registration step using the Elastix software (5.1.0) [34]. This critical process ensured precise correspondence between each anatomical point in both imaging modalities.
* MR and CT images were padded (zero-padding for MR images and \(-\)1024-padding for CT images) to achieve the same matrix size for all volumes, ensuring compatibility with the CycleGAN input size. This step was crucial in establishing a consistent resolution (256 \(\times\) 256 \(\times\) 256 voxels) across all images, effectively preventing information loss during subsequent procedures.
* CT intensity normalization was conducted to adjust the HU range from \(-\)1024 to 3071, using MATLAB (The MathWorks Inc., Natick, USA). This normalization was performed to ensure a fixed representation of 4096 gray levels, including the range for tissues.
* MR and CT images were used to create a joint mask using MATLAB. This aimed to guarantee coherence in areas where one modality lacked data compared to the other.  
Preprocessed 2D slices were then fed to the CycleGAN, using the Mean Absolute Error (MAE) as loss function, together with the Adam optimizer with a learning rate of \(10^{-4}\), and a batch size of 6. The model was trained for 300 epochs using a cross-validation scheme (k = 4) with 12 patients for training and 4 patients for test in each iteration; although, after epoch 50, the noticeable improvement in image differences reduced, the loss function graph (MAE) continued to converge gradually. The model was trained in a server equipped with an NVIDIA A100 80 GB PCIe Tensor Core GPU. While the training time of the model lasted for one day, the final inference time took around 30 s per patient; this short time for performing inference using the trained model is acceptable for future implementation and deployment in clinical settings.