Processing Computer Tomography (CT) for Deep Learning Applications.

An overview of computed tomography (CT) processing applied to machine learning powered diagnostic imaging tools.

Miguel Ángel Cárdenas
Semantix
5 min readMay 27, 2021

--

Image preprocessing is a fundamental step in any deep learning model building process, especially when it comes to medical images that we heavily rely on such as X-ray and computer tomography(CT). From reading raw DICOM files and anonymizing them to assembly tensor data of the input layer in deep learning networks.

Several machine learning and deep learning applications using medical images still rely on some technologies such as X-ray and computed tomography (CT) for disease diagnosis and prognosis. Building a successful data set using these images depends on image quality aspects such as signal-to-noise ratio (SNR) and intensity homogeneities to perform reasonably. Another important aspect is the link between existing health care systems (e.g. PACS) and medical applications that should comply with privacy regulations.
Most of the medical images are in DICOM (Digital Imaging and Communications in Medicine) format, which is a combination of metadata regarding clinical information and pixel data. The former comes in tuple-like tags denoted by 2 hexadecimal numbers, for instance: (0010,0020) which contains Patient ID; the latter contains pixel spacing and size (usually 512 x 512).
The following is an overview of a typical CT pre-process pipeline for deep learning applications. It assumes, and for the sake of protected data that the original file has been anonymized and goes all the way to creating a tensor-like image representation.

CT image processing pipeline

To show how this pipeline works I will be using SimpleIKT. SimpleITK is a procedural ITK wrapper for python language that has many interesting methods for medical image processing. I have created a GitHub repository for processing CT scans where each method can be accessed as a class member function.

CT scan pre-process class defintion

Anonymization

Anonymizing and de-identifying patient data should be the first step in any medical application pipeline since according to the newest LGPD regulations, sensible data should be avoided when sharing datasets on the internet. These privacy regulations must be in compliance with organizations such as HIPAA in the US and the PIPEDA in Canada. Recently the Radiological Society of North America(RSNA) made available an anonymization tool for such purpose.

Reading DICOM files

SimpleIKT package offers a comprehensive tool for reading DICOM data in a procedural fashion. The following code snippet shows how to read a CT scan and if everything goes well it displays series description from the metadata. For better understanding of DICOM fields check this resource.

DICOM file reading snippet

Converting to NIfTI format

Not very often is needed to work with DICOM files, which is a heavily weighted file format, so is desirable to work with something much more lightweight. NIfTI(Neuroimaging Informatics Technology Initiative) format is a good candidate for the job and it can be read by nearly all medical imaging platforms (e.g mango). Using the snippet before, once the DICOM file is read, it can be saved as *.nii.gz. So let’s save it afterwards.

sitk.WriteImage(ct_scan,OUTPUT_PATH+”ct_scan.nii.gz”)

Mango CT scan visualization

Windowing

Usually, CT data is restricted to the [−1024, 3071] range in Hounsfield Units (HU). Values less than −1024 HU are commonly found due to areas of the image outside the field of view (FOV) of the scanner. The first step towards enhancing the image according to the specific needs would be to Winsorize the data to the [−1024, 3071] range, or whatever is your purpose. The following list shows the most common ranges for some anatomical regions of the body.

Hounsfield instensity level values

The following comparison uses mango for reading the same chest CT scan. The image on the left has a HU window of [-1000,400], and the right has a HU range of [-400,600]. Different ranges enhance some anatomic structures of the lung parenchyma.

There is another possible intensity level transformation called Cormack scale tha was created bry Chris Rorden in his infamous matlab’s clinical toolbox. The following is a numpy-ed version of the original one.

Gantry removal

Sometimes is desirable to perform a tight crop operation to remove the gantry artifacts that could downgrade your feature extraction process that can be done using SimpleITK’s connected components functions

Resample

Encoding a CT scan to be used in a deep learning context, also requires downsampling the original volume to a more proper size that fits the input tensor size. To do it we should resample the volume to keep the same proportions along all the axes. The snippet below uses some functions from the geometric transformations package.

Pseudocolor conversion

Usually, consolidated deep learning architectures for medical images have multiband-like tensors that normally rely on RGB images. When using grayscale images (or even Hounsfield scale) comes in handy the use of pseudo color techniques that may enhance the target features within. This works whether you are using channels_first(NCHW) or channels_last (NHWC) conventions in TensorFlow for instance. The pseudocode (image below) shows how this process works.

The snippet below implements this idea of creating a multi-band image in YCbCr color space for deep learning purposes.

Happy coding!

--

--