- Prerequisites
- Introduction
- Data from CT scans
- Preprocessing
- Building a Convolutional Neural Network
- References
- Install Tensorflow
- Install Tflearn
- Install SimpleITK
- Install PIL (Python Imaging Library)
A computerized tomography (CT) scan consists of a series of X-ray images taken from different angles and combines them to create cross-sectional images, or slices, of the bones, soft tissues, etc. inside our body.
Since CT scans consist of slices which amalgamate a 3D view, this technology allows radiologists to analyze the body in high-resolution 3D representations.
CT scans contain 2D arrays with pixel intensities in DICOM files. However CT scans are not in the standard 0โ255 range, but are instead in HU (Hounsfield Units)
HU measure the radio-intensity of particular mediums based on their attenuation coefficients. Attenuation coefficients give a measure of how easily X-rays can pass through a particular medium.
They range from -1000 HU for air, to 0 HU for distilled water. In our case Lung CT scans, we have the following range:
- Max HU: 400
- Min HU: -1000
Once we clamp our input to a particular intensity window range as a preprocessing step, we can normalize the resulting data to 0โ255 and produce an image which can be used to train machine learning models.
We are going to use the LUNA16 dataset which contains 888 CT scans. The images have a .mhd format and .raw files. The SimpleITK library can be used to read the .mhd files. Each CT scan has dimensions of 512x512xn, where n is the number of axial scans. There are about 200 images in each CT scan.
There are a total of 551065 annotations. Of all the annotations provided, 1351 were labeled as nodules, rest were labeled negative (549714). So there big class imbalance.
We could potentially train the CNN on all the pixels, but that would increase the computational cost and training time. So instead I just decided to crop the images around the coordinates provided in the annotations. The annotation were provided in Cartesian coordinates. So they had to be converted to voxel coordinates. Also the image intensity was defined in HU scale. So it had to be rescaled for image processing purposes.
The script would generate 50 x 50 grayscale images for training, testing and validating a CNN.
For building a CNN Tflearn will be used. Tflearn is a high-level API wrapper around tensorflow. Using a 3 convolutional layers in the architecture.