CT Scan Utilities. A set of useful methods for working with CT scan dicom files as simple as possible in python.
dependencies:
- pydicom
- numpy
- scipy
- matplotlib
- plotly
Read a single slice from a CT Scan:
from ctu import reader
slice = reader.ReadSlice("path to CT slice")
print(slice)
slice is a dicom DataSet object that contains pixel data and other metadata. Dataset object is the primary object and is used in many methods.
Read a CT scan
from ctu import reader
ct_slices = reader.ReadCT("path to a CT Scan directory")
print(len(ct_slices))
Plot Slices of a CT Scan:
from ctu import reader, display
slices = reader.ReadCT("path to a CT Scan directory")
display.PlotSlices(slices,wtype='lung',nrows=5,ncols=5, step=2)
Working with Image data
Get image in Hounsfield scale:
from ctu import reader, display
slice = reader.ReadSlice("path to a slice")
img = reader.getImageHU(slice)
display.Plot(img)
Get image in a certain Windowing condition:
from ctu import reader, display
slice = reader.ReadSlice("path to slice")
img = reader.getWindowedImage(slice, wtype='lung')
display.Plot(img)
Plot a CT Scan in 3D
from ctu import reader, display
slices = reader.ReadCT("path to a CT Scan folder")
display.Plot3D(slices, threshold=400)
Mask body part in CT slices
from ctu import reader, transform
slice = reader.ReadSlice("path to a slice")
img = reader.getWindowedImage(slice, 'lung')
mask, masked_image = transform.BodyMask(img)
Lung mask of a CT Slice
from ctu import reader, transform
slice = reader.ReadSlice("path to a slice")
img = reader.getImageHU(slice)
label, mask, masked_image = transform.LungMask(img)