0

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

OtagoHarbour
  • 3,969
  • 6
  • 43
  • 81

1 Answers1

2

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.

darcymason
  • 1,223
  • 6
  • 9
  • Thank you for your reply. Unfortunately, "print(image.TransferSyntaxUID)" resulted in "AttributeError: 'FileDataset' object has no attribute 'TransferSyntaxUID'" on Spyder. Thanks, – OtagoHarbour Dec 15 '19 at 19:04
  • 1
    Sorry, should be `print(image.file_meta.TransferSyntaxUID)` – darcymason Dec 16 '19 at 01:47
  • So the footnote in the supported syntaxes table indicates that is not supported with Pillow if > 8-bit. Likely your MR format is 12-bit. `image.BitsStored` can confirm that. If it is, you would have to have GDCM available for pydicom to work with it. – darcymason Dec 16 '19 at 15:46
  • Yes indeed. It is 12-bit. I will try to get GDCM. Thanks, – OtagoHarbour Dec 16 '19 at 16:28