This code is for 3D lung segmentation in CT scans using a U-Net model. The dataset consists of 45 patient lung CT scans and their respective masks. The masks contain three labels: trachea, left lung, and right lung. The initial tasks involve removing the trachea (label 5) and merging labels 3 and 4 into one, resulting in a lung mask.
The preprocessing steps include:
- Trachea Removal: Remove the trachea from the masks.
- Label Merge: Combine labels 3 and 4 into a single label.
- Save Lung Masks: Save the modified lung masks.
The model can be trained in three different ways:
- Individual Training: Train the model with individual CT scan images and masks.
- Subvolume Training: Divide or create subvolumes of smaller size and feed them to the model.
- 2D Slice Training: Slice the 3D image into 2D images, train the 2D images, and then combine them to form the 3D model.
In this project, the third approach is followed for computational efficiency.
Before training, the CT scan images are analyzed. The image values range from -3500 to 3500 Hounsfield units, requiring normalization. After normalization, the images are segmented into 2D images in all axes (x, y, z) and stored in separate folders.
For training data, the sliced images need to be split into training and testing sets. In this project, 80% of the data (36 patients out of 45) is used for training, and 20% (9 patients out of 45) is used for testing.
A U-Net model with four layers is created and trained on the prepared dataset. Once training is complete, the model can be used for segmentation.
The trained model is used to predict a single sliced image. Based on the predictions, a 3D model image is generated. When a 3D image is provided, it will be sliced, segmented in that particular cross-section, and the values will be combined to return the 3D segmented image from the CT scan.