# Computer Tools to Analyze Lung CT Changes after Radiotherapy
## 5 System Implementation
### Registration
#### 5.2.1 Affine Slice Registration  
Firstly, we analyzed the whole previously segmented images not as solid 3D figures, but as individual slices. Each pair of corresponding slices was registered, where the image from the after series was treated as moving_image and the one from the before series as fixed_image. For this task, we also used the SITK library [30]. Before executing the registration algorithm, many parameters had to be specified:  
1. Initial transformation: In this step, we used CenteredTransformInitializer in order to align the centers of both slices. At the same time, the AffineTransform transformation type was chosen. Transformations like Euler2 DTransform would not be proper in this case, because both series were acquired by different devices, which means they had various scales. Euler transformation is specified as rotation and translation, but without scaling. As seen in Figure 15, lungs on the \"before\" series were much smaller those on the \"after\" series, so scaling was one of the most significant needed transformations.
2. Measure metric: We used MattesMutualInformation. The metric sampling strategy was set to REGULAR, and the metric sampling percent was set to 100%. That means that to calculate the current measure, all pixels were taken into consideration. Due to the fact that lung segmentation was performed before registration, we could not compute the metric using a small percent of random points, as was proposed in [31]. If only black points (outside the lungs) had been randomly chosen from both images, then the cost function would have been very low, but it would not mean that the lungs were properly registered.
3. Interpolator: We set it as Linear. In most cases, linear interpolation is the default setting. It gives a weighted average of surrounding voxels with the usage of distances as weights.
4. Optimizer: The gradient descent optimizer was chosen for affine registration. It has many parameters to be set, and we used the following: * learningRate = 1, * numberOfIterations = 255.
5. Multi-resolution framework: The last set parameters were associated with the multi-resolution framework, which the SITK library provides. Due to this strategy, we were able to improve the robustness and the capture range of the registration process. The input image was firstly significantly smoothed and had a low resolution. Then, during the next iterations, it became less smoothed, and the resolution increased. This additional multi-resolution utility was realized with two functions: SetShrinkFactorsPerLevel (shrink factors applied at the change of level)  
Figure 14: Segmented lungs in Slice No. 66 (end of the series).  
and SetSmoothingSignasPerLevel (smoothing sigmas applied also at the change of level--in voxels or physical units). In affine registration, where the images differed significantly from each other, we decided to set four multi-resolution levels. The chosen parameters were as follows:  
* shrinkFactors = [6,4,2,1],
* smoothingSignas = [3,2,1,0].  
We executed this algorithm for each pair of corresponding slices. An example of an image before and after affine transformation is shown in Figure 16. The time of affine registration for one slice was 2.5 s, and the total time of affine registration for the whole series was 168.1 s.  
Table 6 presents the SimpleITK \"one slice\" affine registration results.  
\begin{table}
\begin{tabular}{c c} \hline \hline
**Parameter** & **Value** \\ \hline Transformation & “Affine” \\ Final metric value & \(-0.4329\) \\ Total registration time & \(2.5\) s \\ \hline \hline \end{tabular}
\end{table}
Table 6: Result of one slice affine registration using SimpleITK.  
Figure 16: Illustration of the registration results using the SimpleITK library.  
Figure 15: Illustration of the size difference in before and after slices.