## 5 Case Study of Developing Liver Cancer Diagnosis
### Customizing the Platform for HCC Diagnosis
#### 5.2.3 Refining the Diagnosis Manager for HCC Diagnosis  
The platform defines the design of _Diagnosis Manager_ by applying the Template Method Pattern, as shown in Figure 7. To specialize, the eight abstract methods defined in the super-class _Diagnosis Manager_ were implemented in a subclass for the purpose of diagnosing HCC.  
The design of _HCC Diagnosis Manager_ by specializing _Diagnosis Manager_ is shown in Figure 9.  
The class _HCC_Diagnosis_Manager_ is defined as a subclass, and it implements the eight abstracts for HCC diagnosis by applying the guidelines of the LI-RADS standard. We use the numpy library for handling arrays and the keras for leveraging deep learning models.  
For example, the implementation of the method for segmenting tumors from lesions found in CT slices, _segment_tumor()_, is shown in Figure 10.  
\begin{table}
\begin{tabular}{c c c c c c} \hline \hline
**Category** & **Probability** & & \multicolumn{2}{c}{**Imaging Features**} & \multicolumn{2}{c}{**Management**} \\ \hline \multirow{3}{*}{**LR-5**} & \multirow{3}{*}{**Definitely HCC**} & \(\bullet\) & Mass HYPERenhancing in the arterial phase: & & \(\bullet\) & Multidisciplinary \\  & & \(\bigcirc\) & 10-19 mm with \(\geq\)2 of WCT & & & discussion \\  & & \(\bigcirc\) & \(\geq\)20 mm with \(\geq\)1 of WCT & & & \\ \hline \multirow{3}{*}{**LR-5V**} & \multirow{3}{*}{**Tumor in Vein**} & \multirow{3}{*}{\(\bullet\)} & \multirow{3}{*}{Definite enhancing soft tissue in vein} & \(\bullet\) & Multidisciplinary \\  & & & & & discussion \\ \cline{3-5}  & & & & & Contrainication to \\ \hline \multirow{6}{*}{**LR-M**} & \multirow{6}{*}{**Probable Malignancy, but Non-specific for HCC**} & \multicolumn{2}{c}{Favor HCC:} & & \\  & & & Favor other malignancy: & \(\bullet\) & Diffuse arterial & \\  & & \(\bullet\) & Arterial rim & HYPERenhancement & \\  & & & HYPERenhancement & \(\bullet\) & Delayed washout & \\  & & \(\bullet\) & Central delayed phase & \(\bullet\) & Capsule & \\  & & \(\bullet\) & enhancement & \(\bullet\) & Distinct rim & \\  & & \(\bullet\) & Concentric enhancement & \(\bullet\) & Intralesional fat & \\  & & \(\bullet\) & Peripheral washout & \(\bullet\) & Diffuse T1 & \\  & & \(\bullet\) & Hepatic retraction & HYPERintensity & \\  & & \(\bullet\) & Biliary obstruction & \(\bullet\) & Tumor in vein & \\  & & \(\bullet\) & greater than expected & \(\bullet\) & Nodule-in-nodule & \\  & & \(\bullet\) & Targetoid on DWI or & \(\bullet\) & Mosaic architecture & \\  & & \(\bullet\) & hepatobiliary phase & \(\bullet\) & Spontaneous & \\  & & & hemorrhage & & \\ \hline \hline \end{tabular}
\end{table}
Table 3: _Cont._1. import numpy as np
2. import cv2
3. from tensorflow.keras.models import load_model
4.
5. # load the pre-trained CNN model for tumor segmentation
6. tumor_seg_model = load_model[file_slices_lesions]
7.
8. # Preprocess the CT slice to be suitable for the model input.
9. def preprocess_image(ct_slice):
10. # Resize the image to the required size for the model, e.g., \(256\times 256\)
11. ct_slice_resized = cv2.resize(ct_slice, (256, 256))
12.
13. # Normalize the image to the range the model expects, e.g., 0-1
14. ct_slice_normalized = ct_slice_resized/255.0
15.
16. # Expand the dimensions to fit the model input shape, e.g., (1, 256, 256, 1)
17. ct_slice_expanded = np.expand_dims(ct_slice_normalized, axis = 0)
18. return ct_slice_expanded
19.
20. # Segment tumor in a CT slice using the CNN-based model.
21. def segment_tumor(ct_slice):
22. # Preprocess the CT slice
23. processed_slice = preprocess_image(ct_slice)
24.
25. # Perform prediction (segmentation)
26. segmentation = tumor_seg_model.predict(processed_slice)
27.
28. # Post-process to create a binary mask, in the range [0, 1]
29. segmentation_mask = {segmentation [0] > 0.5}.astype(np.uint8)
30. return segmentation_mask  
Figure 10: Python program for specializing segment_tumor().  
Figure 9: Specializing the diagnosis manager for HCC liver cancer diagnosis.  
CT slices for segmentation in line #9, and segmenting tumors by invoking the _'predict()'_ method in line #26.