pydicom 'Dataset' object has no attribute 'TransferSyntaxUID'

☆樱花仙子☆ 提交于 2019-12-11 08:00:41

问题


I'm using pydicom 1.0.0a1, downloaded from here, When I run the following code:

ds=pydicom.read_file('./DR/abnormal/abc.dcm',force=True)
ds.pixel_array

this error occurs:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-6-d4e81d303439> in <module>()
      7 ds=pydicom.read_file('./DR/abnormal/abc.dcm',force=True)
      8 
----> 9 ds.pixel_array
     10 

/Applications/anaconda/lib/python2.7/site-packages/pydicom-1.0.0a1-py2.7.egg/pydicom/dataset.pyc in __getattr__(self, name)
    501         if tag is None: # `name` isn't a DICOM element keyword
    502             # Try the base class attribute getter (fix for issue 332)
--> 503             return super(Dataset, self).__getattribute__(name)
    504         tag = Tag(tag)
    505         if tag not in self: # DICOM DataElement not in the Dataset

/Applications/anaconda/lib/python2.7/site-packages/pydicom-1.0.0a1-py2.7.egg/pydicom/dataset.pyc in pixel_array(self)
   1064             The Pixel Data (7FE0,0010) as a NumPy ndarray.
   1065         """
-> 1066         return self._get_pixel_array()
   1067 
   1068     # Format strings spec'd according to python string formatting options

/Applications/anaconda/lib/python2.7/site-packages/pydicom-1.0.0a1-py2.7.egg/pydicom/dataset.pyc in _get_pixel_array(self)
   1042         elif self._pixel_id != id(self.PixelData):
   1043             already_have = False
-> 1044         if not already_have and not self._is_uncompressed_transfer_syntax():
   1045             try:
   1046                 # print("Pixel Data is compressed")

/Applications/anaconda/lib/python2.7/site-packages/pydicom-1.0.0a1-py2.7.egg/pydicom/dataset.pyc in _is_uncompressed_transfer_syntax(self)
    662         """Return True if the TransferSyntaxUID is a compressed syntax."""
    663         # FIXME uses file_meta here, should really only be thus for FileDataset
--> 664         return self.file_meta.TransferSyntaxUID in NotCompressedPixelTransferSyntaxes
    665 
    666     def __ne__(self, other):

/Applications/anaconda/lib/python2.7/site-packages/pydicom-1.0.0a1-py2.7.egg/pydicom/dataset.pyc in __getattr__(self, name)
    505         if tag not in self: # DICOM DataElement not in the Dataset
    506             # Try the base class attribute getter (fix for issue 332)
--> 507             return super(Dataset, self).__getattribute__(name)
    508         else:
    509             return self[tag].value

AttributeError: 'Dataset' object has no attribute 'TransferSyntaxUID'

I read the google group post , and I changed the filereader.py file to the posted file, and I got this error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Applications/anaconda/lib/python2.7/site-packages/pydicom-1.0.0a1-py2.7.egg/pydicom/__init__.py", line 41, in read_file
    from pydicom.dicomio import read_file
  File "/Applications/anaconda/lib/python2.7/site-packages/pydicom-1.0.0a1-py2.7.egg/pydicom/dicomio.py", line 3, in <module>
    from pydicom.filereader import read_file, read_dicomdir
  File "/Applications/anaconda/lib/python2.7/site-packages/pydicom-1.0.0a1-py2.7.egg/pydicom/filereader.py", line 35, in <module>
    from pydicom.datadict import dictionaryVR
ImportError: cannot import name dictionaryVR 

Does anybody know how to solve this problem?


回答1:


You should set the TransferSyntaxUID after reading the file before trying to get the pixel_array.

import pydicom.uid
ds=pydicom.read_file('./DR/abnormal/abc.dcm',force=True)
ds.file_meta.TransferSyntaxUID = pydicom.uid.ImplicitVRLittleEndian  # or whatever is the correct transfer syntax for the file
ds.pixel_array

The correction from the post you referenced was done before some changes in the code to harmonize some naming, so the error is thrown because the current master uses dictionary_VR rather than dictionaryVR. Setting the transfer syntax in user code as above avoids that problem.



来源:https://stackoverflow.com/questions/44492420/pydicom-dataset-object-has-no-attribute-transfersyntaxuid

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!