本文整理汇总了Python中pydicom.dataset.Dataset.get方法的典型用法代码示例。如果您正苦于以下问题:Python Dataset.get方法的具体用法?Python Dataset.get怎么用?Python Dataset.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pydicom.dataset.Dataset
的用法示例。
在下文中一共展示了Dataset.get方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testGetFromRaw
# 需要导入模块: from pydicom.dataset import Dataset [as 别名]
# 或者: from pydicom.dataset.Dataset import get [as 别名]
def testGetFromRaw(self):
"""Dataset: get(tag) returns same object as ds[tag] for raw element."""
# This came from issue 88, where get(tag#) returned a RawDataElement,
# while get(name) converted to a true DataElement
test_tag = 0x100010
test_elem = RawDataElement(Tag(test_tag), "PN", 4, b"test", 0, True, True)
ds = Dataset({Tag(test_tag): test_elem})
by_get = ds.get(test_tag)
by_item = ds[test_tag]
msg = "Dataset.get() returned different objects for ds.get(tag) " "and ds[tag]:\nBy get():%r\nBy ds[tag]:%r\n"
self.assertEqual(by_get, by_item, msg % (by_get, by_item))
示例2: read_partial
# 需要导入模块: from pydicom.dataset import Dataset [as 别名]
# 或者: from pydicom.dataset.Dataset import get [as 别名]
def read_partial(fileobj, stop_when=None, defer_size=None, force=False):
"""Parse a DICOM file until a condition is met.
Parameters
----------
fileobj : a file-like object
Note that the file will not close when the function returns.
stop_when :
Stop condition. See ``read_dataset`` for more info.
defer_size : int, str, None, optional
See ``read_file`` for parameter info.
force : boolean
See ``read_file`` for parameter info.
Notes
-----
Use ``read_file`` unless you need to stop on some condition
other than reaching pixel data.
Returns
-------
FileDataset instance or DicomDir instance.
See Also
--------
read_file
More generic file reading function.
"""
# Read preamble -- raise an exception if missing and force=False
preamble = read_preamble(fileobj, force)
file_meta_dataset = Dataset()
# Assume a transfer syntax, correct it as necessary
is_implicit_VR = True
is_little_endian = True
if preamble:
file_meta_dataset = _read_file_meta_info(fileobj)
transfer_syntax = file_meta_dataset.TransferSyntaxUID
if transfer_syntax == pydicom.uid.ImplicitVRLittleEndian:
pass
elif transfer_syntax == pydicom.uid.ExplicitVRLittleEndian:
is_implicit_VR = False
elif transfer_syntax == pydicom.uid.ExplicitVRBigEndian:
is_implicit_VR = False
is_little_endian = False
elif transfer_syntax == pydicom.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 = fileobj.read()
# -MAX_WBITS part is from comp.lang.python answer:
# groups.google.com/group/comp.lang.python/msg/e95b3b38a71e6799
unzipped = zlib.decompress(zipped, -zlib.MAX_WBITS)
fileobj = BytesIO(unzipped) # a file-like object
is_implicit_VR = False
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)
is_implicit_VR = False
else: # no header -- use the is_little_endian, implicit assumptions
file_meta_dataset.TransferSyntaxUID = pydicom.uid.ImplicitVRLittleEndian
try:
dataset = read_dataset(fileobj, is_implicit_VR, is_little_endian,
stop_when=stop_when, defer_size=defer_size)
except EOFError:
pass # error already logged in read_dataset
class_uid = file_meta_dataset.get("MediaStorageSOPClassUID", None)
if class_uid and class_uid == "Media Storage Directory Storage":
return DicomDir(fileobj, dataset, preamble, file_meta_dataset,
is_implicit_VR, is_little_endian)
else:
return FileDataset(fileobj, dataset, preamble, file_meta_dataset,
is_implicit_VR, is_little_endian)
示例3: read_partial
# 需要导入模块: from pydicom.dataset import Dataset [as 别名]
# 或者: from pydicom.dataset.Dataset import get [as 别名]
def read_partial(fileobj, stop_when=None, defer_size=None, force=False):
"""Parse a DICOM file until a condition is met.
Parameters
----------
fileobj : a file-like object
Note that the file will not close when the function returns.
stop_when :
Stop condition. See ``read_dataset`` for more info.
defer_size : int, str, None, optional
See ``read_file`` for parameter info.
force : boolean
See ``read_file`` for parameter info.
Notes
-----
Use ``read_file`` unless you need to stop on some condition
other than reaching pixel data.
Returns
-------
FileDataset instance or DicomDir instance.
See Also
--------
read_file
More generic file reading function.
"""
# Read preamble -- raise an exception if missing and force=False
preamble = read_preamble(fileobj, force)
file_meta_dataset = Dataset()
# Assume a transfer syntax, correct it as necessary
is_implicit_VR = True
is_little_endian = True
if preamble:
file_meta_dataset = _read_file_meta_info(fileobj)
transfer_syntax = file_meta_dataset.get("TransferSyntaxUID")
if transfer_syntax is None: # issue 258
# Assume and set ImplicitVRLittleEndian transfer syntax
file_meta_dataset.TransferSyntaxUID = \
pydicom.uid.ImplicitVRLittleEndian
elif transfer_syntax == pydicom.uid.ImplicitVRLittleEndian:
pass
elif transfer_syntax == pydicom.uid.ExplicitVRLittleEndian:
is_implicit_VR = False
elif transfer_syntax == pydicom.uid.ExplicitVRBigEndian:
is_implicit_VR = False
is_little_endian = False
elif transfer_syntax == pydicom.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 = fileobj.read()
# -MAX_WBITS part is from comp.lang.python answer:
# groups.google.com/group/comp.lang.python/msg/e95b3b38a71e6799
unzipped = zlib.decompress(zipped, -zlib.MAX_WBITS)
fileobj = BytesIO(unzipped) # a file-like object
is_implicit_VR = False
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)
is_implicit_VR = False
else: # no header -- use the is_little_endian, implicit assumptions
file_meta_dataset.TransferSyntaxUID = pydicom.uid.ImplicitVRLittleEndian
endian_chr = "<"
element_struct = Struct(endian_chr + "HH2sH")
# Try reading first 8 bytes
group, elem, VR, length = element_struct.unpack(fileobj.read(8))
# Rewind file object
fileobj.seek(0)
# If the VR is a valid VR, assume Explicit VR transfer systax
from pydicom.values import converters
if not in_py2:
VR = VR.decode(default_encoding)
if VR in converters.keys():
is_implicit_VR = False
# Determine if group in low numbered range (Little vs Big Endian)
if group == 0: # got (0,0) group length. Not helpful.
# XX could use similar to http://www.dclunie.com/medical-image-faq/html/part2.html code example
msg = ("Not able to guess transfer syntax when first item "
"is group length")
raise NotImplementedError(msg)
if group < 2000:
file_meta_dataset.TransferSyntaxUID = pydicom.uid.ExplicitVRLittleEndian
else:
file_meta_dataset.TransferSyntaxUID = pydicom.uid.ExplicitVRBigEndian
is_little_endian = False
try:
dataset = read_dataset(fileobj, is_implicit_VR, is_little_endian,
stop_when=stop_when, defer_size=defer_size)
except EOFError:
pass # error already logged in read_dataset
class_uid = file_meta_dataset.get("MediaStorageSOPClassUID", None)
if class_uid and class_uid == "Media Storage Directory Storage":
#.........这里部分代码省略.........