Search code examples
pythondicompydicom

Reading 3D DICOM volume, from single file, into numpy array


I am using Python 3.7.3 on Anaconda Spyder on CentOS 7.

I have a 3D DICOM volume that is in a single file:/usr/share/aliza/datasets/DICOM/00_MR/Tra_FLAIR.dcm

I am trying to read it into a 3D numpy array as described here.

I try the following code

import pydicom as dicom
import numpy as np

image=dicom.read_file('/usr/share/aliza/datasets/DICOM/00_MR/Tra_FLAIR.dcm')
image.pixel_array

This results in

Traceback (most recent call last):

  File "<ipython-input-28-85bf1e993c9b>", line 1, in <module>
    image.pixel_array

  File "/home/peter/anaconda3/lib/python3.7/site-packages/pydicom/dataset.py", line 1362, in pixel_array
    self.convert_pixel_data()

  File "/home/peter/anaconda3/lib/python3.7/site-packages/pydicom/dataset.py", line 1308, in convert_pixel_data
    raise last_exception

  File "/home/peter/anaconda3/lib/python3.7/site-packages/pydicom/dataset.py", line 1276, in     convert_pixel_data
    arr = handler.get_pixeldata(self)

  File "/home/peter/anaconda3/lib/python3.7/site-    packages/pydicom/pixel_data_handlers/pillow_handler.py", line 187, in get_pixeldata
    raise NotImplementedError(e.strerror)

NotImplementedError: None

My understanding is that the python package, dicom, is simply pydicom 0.9.9 or earlier and when I do a search for dicom, here, all the hits are for pydicom


Solution

  • This is most likely a problem with the image handler (Pillow in this case) not handling the compression type.

    Please see the Supported Transfer Syntax page in the current stable branch of the documentation - the link you showed is for an older version. If you have an older version of pydicom, please update - the image handling (and error messages) have been improving each version.

    You can use print(image.file_meta.TransferSyntaxUID) to see which type you have and determine from that table which handlers can support it.