本文整理匯總了Python中dicom.dataset.Dataset.keys方法的典型用法代碼示例。如果您正苦於以下問題:Python Dataset.keys方法的具體用法?Python Dataset.keys怎麽用?Python Dataset.keys使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類dicom.dataset.Dataset
的用法示例。
在下文中一共展示了Dataset.keys方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: DicomIter
# 需要導入模塊: from dicom.dataset import Dataset [as 別名]
# 或者: from dicom.dataset.Dataset import keys [as 別名]
class DicomIter(object):
"""Iterator over DICOM data elements created from a file-like object
"""
def __init__(self, fp, stop_when=None, force=False):
"""Read the preambleand meta info, prepare iterator for remainder
fp -- an open DicomFileLike object, at start of file
Adds flags to fp: Big/Little-endian and Implicit/Explicit VR
"""
self.fp = fp
self.stop_when = stop_when
self.preamble = preamble = read_preamble(fp, force)
self.has_header = has_header = (preamble is not None)
self.file_meta_info = Dataset()
if has_header:
self.file_meta_info = file_meta_info = _read_file_meta_info(fp)
transfer_syntax = file_meta_info.TransferSyntaxUID
if transfer_syntax == dicom.UID.ExplicitVRLittleEndian:
self._is_implicit_VR = False
self._is_little_endian = True
elif transfer_syntax == dicom.UID.ImplicitVRLittleEndian:
self._is_implicit_VR = True
self._is_little_endian = True
elif transfer_syntax == dicom.UID.ExplicitVRBigEndian:
self._is_implicit_VR = False
self._is_little_endian = False
elif transfer_syntax == dicom.UID.DeflatedExplicitVRLittleEndian:
# See PS3.6-2008 A.5 (p 71) -- when written, the entire dataset following
# the file metadata was prepared the normal way, then "deflate" compression applied.
# All that is needed here is to decompress and then use as normal in a file-like object
zipped = fp.read()
# -MAX_WBITS part is from comp.lang.python answer: http://groups.google.com/group/comp.lang.python/msg/e95b3b38a71e6799
unzipped = zlib.decompress(zipped, -zlib.MAX_WBITS)
fp = StringIO(unzipped) # a file-like object that usual code can use as normal
self.fp = fp #point to new object
self._is_implicit_VR = False
self._is_little_endian = True
else:
# Any other syntax should be Explicit VR Little Endian,
# e.g. all Encapsulated (JPEG etc) are ExplVR-LE by Standard PS 3.5-2008 A.4 (p63)
self._is_implicit_VR = False
self._is_little_endian = True
else: # no header -- make assumptions
fp.TransferSyntaxUID = dicom.UID.ImplicitVRLittleEndian
self._is_little_endian = True
self._is_implicit_VR = True
logger.debug("Using %s VR, %s Endian transfer syntax" %(("Explicit", "Implicit")[self._is_implicit_VR], ("Big", "Little")[self._is_little_endian]))
def __iter__(self):
tags = sorted(self.file_meta_info.keys())
for tag in tags:
yield self.file_meta_info[tag]
for data_element in data_element_generator(self.fp, self._is_implicit_VR,
self._is_little_endian,
stop_when=self.stop_when):
yield data_element
示例2: test_anonymize_dicom
# 需要導入模塊: from dicom.dataset import Dataset [as 別名]
# 或者: from dicom.dataset.Dataset import keys [as 別名]
def test_anonymize_dicom():
anon_tags = [\
Tag(0x0008, 0x0014), # Instance Creator UID
Tag(0x0008, 0x0018), # SOP Instance UID
Tag(0x0008, 0x0050), # Accession Number
Tag(0x0008, 0x0080), # Institution Name
Tag(0x0008, 0x0081), # Institution Address
Tag(0x0008, 0x0090), # Referring Physician's Name
Tag(0x0008, 0x0092), # Referring Physician's Address
Tag(0x0008, 0x0094), # Referring Physician's Telephone Numbers
Tag(0x0008, 0x1010), # Station Name
Tag(0x0008, 0x1030), # Study Description
Tag(0x0008, 0x103E), # Series Description
Tag(0x0008, 0x1040), # Institutional Department Name
Tag(0x0008, 0x1048), # Physician(s) of Record
Tag(0x0008, 0x1050), # Performing Physicians' Name
Tag(0x0008, 0x1060), # Name of Physician(s) Reading Study
Tag(0x0008, 0x1070), # Operators' Name
Tag(0x0008, 0x1080), # Admitting Diagnoses Description
Tag(0x0008, 0x1155), # Referenced SOP Instance UID
Tag(0x0008, 0x2111), # Derivation Description
Tag(0x0010, 0x0010), # Patient's Name
Tag(0x0010, 0x0020), # Patient ID
Tag(0x0010, 0x0030), # Patient's Birth Date
Tag(0x0010, 0x0032), # Patient's Birth Time
Tag(0x0010, 0x0040), # Patient's Sex
Tag(0x0010, 0x1000), # Other Patient Ids
Tag(0x0010, 0x1001), # Other Patient Names
Tag(0x0010, 0x1010), # Patient's Age
Tag(0x0010, 0x1020), # Patient's Size
Tag(0x0010, 0x1030), # Patient's Weight
Tag(0x0010, 0x1090), # Medical Record Locator
Tag(0x0010, 0x2160), # Ethnic Group
Tag(0x0010, 0x2180), # Occupation
Tag(0x0010, 0x21B0), # Additional Patient's History
Tag(0x0010, 0x4000), # Patient Comments
Tag(0x0018, 0x1000), # Device Serial Number
Tag(0x0018, 0x1030), # Protocol Name
Tag(0x0020, 0x000D), # Study Instance UID
Tag(0x0020, 0x000E), # Series Instance UID
Tag(0x0020, 0x0010), # Study ID
Tag(0x0020, 0x0052), # Frame of Reference UID
Tag(0x0020, 0x0200), # Synchronization Frame of Reference UID
Tag(0x0020, 0x4000), # Image Comments
Tag(0x0040, 0x0275), # Request Attributes Sequence
Tag(0x0040, 0xA124), # UID
Tag(0x0040, 0xA730), # Content Sequence
Tag(0x0088, 0x0140), # Storage Media File-set UID
Tag(0x3006, 0x0024), # Referenced Frame of Reference UID
Tag(0x3006, 0x00C2)] # Related Frame of Reference UID
ds = Dataset()
if hasattr(ds, 'AddNew'):
ds.AddNew(Tag(0x0008, 0x0018), 'dicom.UID.UID', 'TestAnonymization')
ds.AddNew(Tag(0x0008, 0x0080), 'str', 'TestAnonymization')
ds.AddNew(Tag(0x0008, 0x0081), 'str', 'TestAnonymization')
ds.AddNew(Tag(0x0008, 0x1010), 'str', 'TestAnonymization')
ds.AddNew(Tag(0x0008, 0x1030), 'str', 'TestAnonymization')
ds.AddNew(Tag(0x0008, 0x103e), 'str', 'TestAnonymization')
ds.AddNew(Tag(0x0010, 0x0010), 'dicom.valuerep.PersonName', 'TestAnonymization')
ds.AddNew(Tag(0x0010, 0x0020), 'str', 'TestAnonymization')
ds.AddNew(Tag(0x0010, 0x0040), 'str', 'TestAnonymization')
ds.AddNew(Tag(0x0010, 0x1010), 'str', 'TestAnonymization')
ds.AddNew(Tag(0x0018, 0x1000), 'str', 'TestAnonymization')
ds.AddNew(Tag(0x0018, 0x1030), 'str', 'TestAnonymization')
ds.AddNew(Tag(0x0020, 0x000d), 'dicom.UID.UID', 'TestAnonymization')
ds.AddNew(Tag(0x0020, 0x000e), 'dicom.UID.UID', 'TestAnonymization')
ds.AddNew(Tag(0x0020, 0x0052), 'dicom.UID.UID', 'TestAnonymization')
ds.AddNew(Tag(0x0020, 0x4000), 'str', 'TestAnonymization')
else:
ds.add_new(Tag(0x0008, 0x0018), 'dicom.UID.UID', 'TestAnonymization')
ds.add_new(Tag(0x0008, 0x0080), 'str', 'TestAnonymization')
ds.add_new(Tag(0x0008, 0x0081), 'str', 'TestAnonymization')
ds.add_new(Tag(0x0008, 0x1010), 'str', 'TestAnonymization')
ds.add_new(Tag(0x0008, 0x1030), 'str', 'TestAnonymization')
ds.add_new(Tag(0x0008, 0x103e), 'str', 'TestAnonymization')
ds.add_new(Tag(0x0010, 0x0010), 'dicom.valuerep.PersonName', 'TestAnonymization')
ds.add_new(Tag(0x0010, 0x0020), 'str', 'TestAnonymization')
ds.add_new(Tag(0x0010, 0x0040), 'str', 'TestAnonymization')
ds.add_new(Tag(0x0010, 0x1010), 'str', 'TestAnonymization')
ds.add_new(Tag(0x0018, 0x1000), 'str', 'TestAnonymization')
ds.add_new(Tag(0x0018, 0x1030), 'str', 'TestAnonymization')
ds.add_new(Tag(0x0020, 0x000d), 'dicom.UID.UID', 'TestAnonymization')
ds.add_new(Tag(0x0020, 0x000e), 'dicom.UID.UID', 'TestAnonymization')
ds.add_new(Tag(0x0020, 0x0052), 'dicom.UID.UID', 'TestAnonymization')
ds.add_new(Tag(0x0020, 0x4000), 'str', 'TestAnonymization')
anonymize_dicom(ds)
keys = ds.keys()
for t in anon_tags:
if t in keys:
assert ds[t].value == 'Anonymized' or ds[t].value == '', \
'Dicom not anonymized'