2017-06-12 281 views
1

我使用pydicom 1.0.0a1,从here下载,当我运行下面的代码:pydicom '数据集' 对象有没有属性 'TransferSyntaxUID'

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' 

我读谷歌组post,我改变了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 

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

+0

是的,我也患有这种疾病。我认为TransferSyntaxUID是一个强制性的事情。您的DICOM文件可能没有设置保存。如果你有MATLAB,可以在DICOM工具箱中正常工作。这将纠正错误。然后重新保存,在Python上再次尝试它 – JessieB

+0

是的,它可以在MATLAB中显示,但是按照您的说法应该如何保存以及如何保存? – user6191682

回答

0

在尝试获取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。如上所述在用户代码中设置传输语法避免了这个问题。