【问题标题】:pydicom 'Dataset' object has no attribute 'TransferSyntaxUID'pydicom 'Dataset' 对象没有属性 'TransferSyntaxUID'
【发布时间】:2017-06-12 06:07:54
【问题描述】:

我正在使用 pydicom 1.0.0a1,从here 下载,当我运行以下代码时:

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'

我读了google群post,把filereader.py文件改成posted文件,出现这个错误:

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 

有人知道如何解决这个问题吗?

【问题讨论】:

  • 是的,我也深受其害。我认为 TransferSyntaxUID 是强制性的。您的 DICOM 文件可能未在保存时设置。如果您有 MATLAB,则可以使用 DICOM 工具箱。这将纠正一个错误。然后重新保存,在 Python 上再试一次
  • 是的,它可以在MATLAB中显示,但是我应该按照你说的保存什么以及如何保存?

标签: python pydicom


【解决方案1】:

您应该在读取文件后设置 TransferSyntaxUID,然后再尝试获取 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

您引用的帖子中的更正是在代码进行一些更改以协调某些命名之前完成的,因此由于当前主人使用dictionary_VR而不是dictionaryVR而引发错误。如上所述在用户代码中设置传输语法可以避免该问题。

【讨论】:

  • 我还是无法访问像素阵列怎么办?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-01
  • 2021-08-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多