本文整理汇总了Python中pydicom.dataset.Dataset.get_item方法的典型用法代码示例。如果您正苦于以下问题:Python Dataset.get_item方法的具体用法?Python Dataset.get_item怎么用?Python Dataset.get_item使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pydicom.dataset.Dataset
的用法示例。
在下文中一共展示了Dataset.get_item方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_item
# 需要导入模块: from pydicom.dataset import Dataset [as 别名]
# 或者: from pydicom.dataset.Dataset import get_item [as 别名]
def test_get_item(self):
"""Test Dataset.get_item"""
# TODO: Add test for deferred read
ds = Dataset()
ds.CommandGroupLength = 120 # 0000,0000
ds.SOPInstanceUID = '1.2.3.4' # 0008,0018
# Test non-deferred read
self.assertEqual(ds.get_item(0x00000000), ds[0x00000000])
self.assertEqual(ds.get_item(0x00000000).value, 120)
self.assertEqual(ds.get_item(0x00080018), ds[0x00080018])
self.assertEqual(ds.get_item(0x00080018).value, '1.2.3.4')
示例2: test_get_item
# 需要导入模块: from pydicom.dataset import Dataset [as 别名]
# 或者: from pydicom.dataset.Dataset import get_item [as 别名]
def test_get_item(self):
"""Test Dataset.get_item"""
ds = Dataset()
ds.CommandGroupLength = 120 # 0000,0000
ds.SOPInstanceUID = '1.2.3.4' # 0008,0018
# Test non-deferred read
assert ds.get_item(0x00000000) == ds[0x00000000]
assert ds.get_item(0x00000000).value == 120
assert ds.get_item(0x00080018) == ds[0x00080018]
assert ds.get_item(0x00080018).value == '1.2.3.4'
# Test deferred read
test_file = get_testdata_files('MR_small.dcm')[0]
ds = dcmread(test_file, force=True, defer_size='0.8 kB')
ds_ref = dcmread(test_file, force=True)
# get_item will follow the deferred read branch
assert ds.get_item((0x7fe00010)).value == ds_ref.PixelData
示例3: test_get_item_slice
# 需要导入模块: from pydicom.dataset import Dataset [as 别名]
# 或者: from pydicom.dataset.Dataset import get_item [as 别名]
def test_get_item_slice(self):
"""Test Dataset.get_item with slice argument"""
# adapted from test_getitem_slice
ds = Dataset()
ds.CommandGroupLength = 120 # 0000,0000
ds.CommandLengthToEnd = 111 # 0000,0001
ds.Overlays = 12 # 0000,51B0
ds.LengthToEnd = 12 # 0008,0001
ds.SOPInstanceUID = '1.2.3.4' # 0008,0018
ds.SkipFrameRangeFlag = 'TEST' # 0008,9460
ds.add_new(0x00090001, 'PN', 'CITIZEN^1')
ds.add_new(0x00090002, 'PN', 'CITIZEN^2')
ds.add_new(0x00090003, 'PN', 'CITIZEN^3')
elem = RawDataElement(0x00090004, 'PN', 9, b'CITIZEN^4', 0, True, True)
ds.__setitem__(0x00090004, elem)
elem = RawDataElement(0x00090005, 'PN', 9, b'CITIZEN^5', 0, True, True)
ds.__setitem__(0x00090005, elem)
elem = RawDataElement(0x00090006, 'PN', 9, b'CITIZEN^6', 0, True, True)
ds.__setitem__(0x00090006, elem)
ds.PatientName = 'CITIZEN^Jan' # 0010,0010
elem = RawDataElement(0x00100020, 'LO', 5, b'12345', 0, True, True)
ds.__setitem__(0x00100020, elem) # Patient ID
ds.ExaminedBodyThickness = 1.223 # 0010,9431
ds.BeamSequence = [Dataset()] # 300A,00B0
ds.BeamSequence[0].PatientName = 'ANON'
# Slice all items - should return original dataset
assert ds.get_item(slice(None, None)) == ds
# Slice starting from and including (0008,0001)
test_ds = ds.get_item(slice(0x00080001, None))
assert 'CommandGroupLength' not in test_ds
assert 'CommandLengthToEnd' not in test_ds
assert 'Overlays' not in test_ds
assert 'LengthToEnd' in test_ds
assert 'BeamSequence' in test_ds
# Slice ending at and not including (0009,0002)
test_ds = ds.get_item(slice(None, 0x00090002))
assert 'CommandGroupLength' in test_ds
assert 'CommandLengthToEnd' in test_ds
assert 'Overlays' in test_ds
assert 'LengthToEnd' in test_ds
assert 0x00090001 in test_ds
assert 0x00090002 not in test_ds
assert 'BeamSequence' not in test_ds
# Slice with a step - every second tag
# Should return zeroth tag, then second, fourth, etc...
test_ds = ds.get_item(slice(None, None, 2))
assert 'CommandGroupLength' in test_ds
assert 'CommandLengthToEnd' not in test_ds
assert 0x00090001 in test_ds
assert 0x00090002 not in test_ds
# Slice starting at and including (0008,0018) and ending at and not
# including (0009,0008)
test_ds = ds.get_item(slice(0x00080018, 0x00090006))
assert 'SOPInstanceUID' in test_ds
assert 0x00090005 in test_ds
assert 0x00090006 not in test_ds
# Slice starting at and including (0008,0018) and ending at and not
# including (0009,0006), every third element
test_ds = ds.get_item(slice(0x00080018, 0x00090008, 3))
assert 'SOPInstanceUID' in test_ds
assert 0x00090001 not in test_ds
assert 0x00090002 in test_ds
assert not test_ds.get_item(0x00090002).is_raw
assert 0x00090003 not in test_ds
assert 0x00090004 not in test_ds
assert 0x00090005 in test_ds
assert test_ds.get_item(0x00090005).is_raw
assert 0x00090006 not in test_ds
# Slice starting and ending (and not including) (0008,0018)
assert ds.get_item(slice((0x0008, 0x0018),
(0x0008, 0x0018))) == Dataset()
# Test slicing using other acceptable Tag initialisations
assert 'SOPInstanceUID' in ds.get_item(slice(0x00080018, 0x00080019))
assert 'SOPInstanceUID' in ds.get_item(slice((0x0008, 0x0018),
(0x0008, 0x0019)))
assert 'SOPInstanceUID' in ds.get_item(slice('0x00080018',
'0x00080019'))