pydicom“数据集”对象没有属性“TransferSyntaxUID”(pydicom '

2019-09-26 01:16发布

我使用pydicom 1.0.0a1,从下载在这里 ,当我运行下面的代码:

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

出现此错误:

---------------------------------------------------------------------------
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'

我读谷歌组后 ,我改变了filereader.py文件的发布文件,我得到这个错误:

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 

有谁知道如何解决这个问题呢?

Answer 1:

你应该设法让pixel_array之前读取文件后设置TransferSyntaxUID。

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

从后您引用的修正尚未开始之前,在代码中的一些变化,以协调一些命名,所以被抛出的错误,因为当前的主用dictionary_VR而非dictionaryVR 。 设置在用户代码传输语法如上避免了这个问题。



文章来源: pydicom 'Dataset' object has no attribute 'TransferSyntaxUID'