Reading Series Data

django_dicom relies on dicom_parser and pydicom’s to convert an Image’s pixel data from bytes to a NumPy ndarray.

Let’s query an anatomical (“MPRAGE”[1]) Series instance we’ve added based on its Series Description:

>>> from django_dicom.models import Series
>>> series = Series.objects.filter(description__contains="MPRAGE").first()

Great! now all we need to do in order to get a NumPy ndarray of the underlying data would be to use the data property:

>>> data = series.get_data()
>>> series.data.shape
(224, 224, 208)

To inspect a particular slice, we could use matplotlib:

>>> import matplotlib.pyplot as plt
>>> plt.imshow(series.data[:, :, 100])
>>> plt.show()

This should return a figure similar to this:

Image could not be retrieved!

Footnotes

[1]Brant-Zawadzki, M., Gillan, G. D., & Nitz, W. R. (1992). MP RAGE: a three-dimensional, T1-weighted, gradient-echo sequence–initial experience in the brain. Radiology, 182(3), 769-775.