本文整理汇总了Python中pydicom.dcmread函数的典型用法代码示例。如果您正苦于以下问题:Python dcmread函数的具体用法?Python dcmread怎么用?Python dcmread使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了dcmread函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: setUp
def setUp(self):
self.mr_small = dcmread(mr_name)
self.mr_rle = dcmread(mr_rle)
self.emri_small = dcmread(emri_name)
self.emri_rle = dcmread(emri_rle)
self.original_handlers = pydicom.config.image_handlers
pydicom.config.image_handlers = [rle_handler, numpy_handler]
开发者ID:kayarre,项目名称:pydicom,代码行数:7,代码来源:test_rle_pixel_data.py
示例2: test_charset_patient_names
def test_charset_patient_names(self, filename, patient_name):
"""Test patient names are correctly decoded and encoded."""
# check that patient names are correctly read
file_path = get_charset_files(filename + '.dcm')[0]
ds = dcmread(file_path)
ds.decode()
assert patient_name == ds.PatientName
# check that patient names are correctly written back
fp = DicomBytesIO()
fp.is_implicit_VR = False
fp.is_little_endian = True
ds.save_as(fp, write_like_original=False)
fp.seek(0)
ds = dcmread(fp)
assert patient_name == ds.PatientName
# check that patient names are correctly written back
# without original byte string (PersonName3 only)
if hasattr(ds.PatientName, 'original_string'):
ds.PatientName.original_string = None
fp = DicomBytesIO()
fp.is_implicit_VR = False
fp.is_little_endian = True
ds.save_as(fp, write_like_original=False)
fp.seek(0)
ds = dcmread(fp)
assert patient_name == ds.PatientName
开发者ID:scaramallion,项目名称:pydicom,代码行数:28,代码来源:test_charset.py
示例3: get_path_info_preview
def get_path_info_preview(self, path):
path_lower = path.lower()
#name
name = os.path.basename(os.path.normpath(path))
name_final = ("name: " + name)
path_sl = path + "/"
if ".jpg" in path_lower:
preview = ("Used path leads to current image.")
img = io.imread(path)
io.imshow(img)
io.show()
elif ".png" in path_lower:
preview = ("Used path leads to current image.")
img = io.imread(path)
io.imshow(img)
io.show()
elif ".dcm" in path_lower:
preview = ("Used path leads to current image.")
ds = pdicom.dcmread(path)
plt.imshow(ds.pixel_array, cmap=plt.cm.bone)
else:
preview = ("Preview of files in dir: " + name)
only_files = [f for f in listdir(path) if isfile(join(path, f))]
for x in only_files:
if (".dcm" or ".Dcm" or ".DCM") in x:
ending = os.path.basename(os.path.normpath(path_sl + x))
preview_path = path_sl + ending
ds = pdicom.dcmread(preview_path)
plt.imshow(ds.pixel_array, cmap=plt.cm.bone)
break
elif (".jpg" or ".Jpg" or ".JPG") in x:
ending = os.path.basename(os.path.normpath(path_sl + x))
preview_path = path_sl + ending
img = io.imread(preview_path)
io.imshow(img)
io.show()
break
elif (".png" or ".Png" or ".PNG") in x:
ending = os.path.basename(os.path.normpath(path_sl + x))
preview_path = path_sl + ending
img = io.imread(preview_path)
io.imshow(img)
io.show()
break
else:
None
break
开发者ID:mjirik,项目名称:io3d,代码行数:54,代码来源:fsbrowser.py
示例4: test_changed_character_set
def test_changed_character_set(self):
# Regression test for #629
multiPN_name = get_charset_files("chrFrenMulti.dcm")[0]
ds = dcmread(multiPN_name) # is Latin-1
ds.SpecificCharacterSet = 'ISO_IR 192'
from pydicom.filebase import DicomBytesIO
fp = DicomBytesIO()
ds.save_as(fp, write_like_original=False)
fp.seek(0)
ds_out = dcmread(fp)
# we expect UTF-8 encoding here
assert b'Buc^J\xc3\xa9r\xc3\xb4me' == ds_out.get_item(0x00100010).value
开发者ID:scaramallion,项目名称:pydicom,代码行数:12,代码来源:test_charset.py
示例5: test_encapsulate_single_fragment_per_frame_bot
def test_encapsulate_single_fragment_per_frame_bot(self):
"""Test encapsulating single fragment per frame with BOT values."""
ds = dcmread(JP2K_10FRAME_NOBOT)
frames = decode_data_sequence(ds.PixelData)
assert len(frames) == 10
data = encapsulate(frames, fragments_per_frame=1, has_bot=True)
test_frames = decode_data_sequence(data)
for a, b in zip(test_frames, frames):
assert a == b
fp = DicomBytesIO(data)
fp.is_little_endian = True
offsets = get_frame_offsets(fp)
assert offsets == [
0x0000, # 0
0x0eee, # 3822
0x1df6, # 7670
0x2cf8, # 11512
0x3bfc, # 15356
0x4ade, # 19166
0x59a2, # 22946
0x6834, # 26676
0x76e2, # 30434
0x8594 # 34196
]
开发者ID:darcymason,项目名称:pydicom,代码行数:26,代码来源:test_encaps.py
示例6: is_CT_slice
def is_CT_slice(file: str) -> bool:
"""Test if the file is a CT Image storage DICOM file."""
try:
ds = pydicom.dcmread(file, force=True, stop_before_pixels=True)
return ds.SOPClassUID.name == 'CT Image Storage'
except (InvalidDicomError, AttributeError, MemoryError):
return False
开发者ID:jrkerns,项目名称:pylinac,代码行数:7,代码来源:image.py
示例7: setup
def setup(self):
# MONOCHROME2, 64x64, 1 sample/pixel, 16 bits allocated, 12 bits stored
self.ds = dcmread(EMRI_RLE_10F)
self.frames = decode_data_sequence(self.ds.PixelData)
assert len(self.frames) == 10
self.no_runs = 100
开发者ID:darcymason,项目名称:pydicom,代码行数:7,代码来源:bench_handler_rle_decode.py
示例8: test_trait_names
def test_trait_names(self):
"""Test Dataset.trait_names contains element keywords"""
test_file = get_testdata_files('CT_small.dcm')[0]
ds = dcmread(test_file, force=True)
names = ds.trait_names()
assert 'PatientName' in names
assert 'save_as' in names
assert 'PixelData' in names
开发者ID:moloney,项目名称:pydicom,代码行数:8,代码来源:test_dataset.py
示例9: is_dicom
def is_dicom(path):
"""Whether the file is a readable DICOM file via pydicom."""
try:
ds = pydicom.dcmread(path, force=True)
ds.pixel_array
return True
except:
return False
开发者ID:jrkerns,项目名称:pylinac,代码行数:8,代码来源:tools.py
示例10: test_decoding_with_specific_tags
def test_decoding_with_specific_tags(self):
"""Decoding is correctly applied even if Specific Character Set
is not in specific tags..."""
rus_file = get_charset_files("chrRuss.dcm")[0]
ds = dcmread(rus_file, specific_tags=['PatientName'])
ds.decode()
assert 2 == len(ds) # specific character set is always decoded
assert u'Люкceмбypг' == ds.PatientName
开发者ID:scaramallion,项目名称:pydicom,代码行数:8,代码来源:test_charset.py
示例11: test_invalid_character_set_enforce_valid
def test_invalid_character_set_enforce_valid(self):
"""charset: raise on invalid encoding"""
config.enforce_valid_values = True
ds = dcmread(get_testdata_files("CT_small.dcm")[0])
ds.read_encoding = None
ds.SpecificCharacterSet = 'Unsupported'
with pytest.raises(LookupError, match='unknown encoding: Unsupported'):
ds.decode()
开发者ID:scaramallion,项目名称:pydicom,代码行数:8,代码来源:test_charset.py
示例12: test_equality_file_meta
def test_equality_file_meta(self):
"""Dataset: equality returns correct value if with metadata"""
d = dcmread(self.test_file)
e = dcmread(self.test_file)
self.assertTrue(d == e)
e.is_implicit_VR = not e.is_implicit_VR
self.assertFalse(d == e)
e.is_implicit_VR = not e.is_implicit_VR
self.assertTrue(d == e)
e.is_little_endian = not e.is_little_endian
self.assertFalse(d == e)
e.is_little_endian = not e.is_little_endian
self.assertTrue(d == e)
e.filename = 'test_filename.dcm'
self.assertFalse(d == e)
开发者ID:moloney,项目名称:pydicom,代码行数:18,代码来源:test_dataset.py
示例13: test_latin1
def test_latin1(self):
"""charset: can read and decode latin_1 file........................"""
ds = dcmread(latin1_file)
ds.decode()
# Make sure don't get unicode encode error on converting to string
expected = u'Buc^J\xe9r\xf4me'
got = ds.PatientName
self.assertEqual(expected, got,
"Expected %r, got %r" % (expected, got))
开发者ID:kayarre,项目名称:pydicom,代码行数:9,代码来源:test_charset.py
示例14: testRead
def testRead(self):
"""Unicode: Can read a file with unicode characters in name..."""
uni_name = u'test°'
# verify first that we could encode file name in this environment
try:
_ = uni_name.encode(sys.getfilesystemencoding())
except UnicodeEncodeError:
print("SKIP: Environment doesn't support unicode filenames")
return
try:
dcmread(uni_name)
except UnicodeEncodeError:
self.fail("UnicodeEncodeError generated for unicode name")
# ignore file doesn't exist error
except IOError:
pass
开发者ID:jrkerns,项目名称:pydicom,代码行数:18,代码来源:test_unicode.py
示例15: assign2machine
def assign2machine(source_file: str, machine_file: str):
"""Assign a DICOM RT Plan file to a specific machine. The source file is overwritten to contain
the machine of the machine file.
Parameters
----------
source_file : str
Path to the DICOM RTPlan file that contains the fields/plan desired
(e.g. a Winston Lutz set of fields or Varian's default PF files).
machine_file : str
Path to a DICOM RTPlan file that has the desired machine. This is easily obtained from pushing a plan from the TPS
for that specific machine. The file must contain at least one valid field.
"""
dcm_source = pydicom.dcmread(source_file)
dcm_machine = pydicom.dcmread(machine_file)
for beam in dcm_source.BeamSequence:
beam.TreatmentMachineName = dcm_machine.BeamSequence[0].TreatmentMachineName
dcm_source.save_as(source_file)
开发者ID:midamo,项目名称:pylinac,代码行数:18,代码来源:utilities.py
示例16: test_get_item
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
开发者ID:moloney,项目名称:pydicom,代码行数:18,代码来源:test_dataset.py
示例17: test_inherited_character_set_in_sequence
def test_inherited_character_set_in_sequence(self):
"""charset: can read and decode SQ with parent encoding............."""
ds = dcmread(get_charset_files('chrSQEncoding1.dcm')[0])
ds.decode()
# These datasets inside of the SQ shall be decoded with the parent
# dataset's encoding
sequence = ds[0x32, 0x1064][0]
assert ['shift_jis', 'iso2022_jp'] == sequence._character_set
assert u'ヤマダ^タロウ=山田^太郎=やまだ^たろう' == sequence.PatientName
开发者ID:scaramallion,项目名称:pydicom,代码行数:10,代码来源:test_charset.py
示例18: test_encoding_with_specific_tags
def test_encoding_with_specific_tags(self):
"""Encoding is correctly applied even if Specific Character Set
is not in specific tags..."""
ds = dcmread(jp_file, specific_tags=['PatientName'])
ds.decode()
self.assertEqual(1, len(ds))
expected = ('Yamada^Tarou='
'\033$B;3ED\033(B^\[email protected]:\033(B='
'\033$B$d$^[email protected]\033(B^\033$B$?$m$&\033(B')
self.assertEqual(expected, ds.PatientName)
开发者ID:kayarre,项目名称:pydicom,代码行数:10,代码来源:test_charset.py
示例19: test_invalid_character_set
def test_invalid_character_set(self):
"""charset: replace invalid encoding with default encoding"""
ds = dcmread(get_testdata_files("CT_small.dcm")[0])
ds.read_encoding = None
ds.SpecificCharacterSet = 'Unsupported'
with pytest.warns(UserWarning,
match=u"Unknown encoding 'Unsupported' "
u"- using default encoding instead"):
ds.decode()
assert u'CompressedSamples^CT1' == ds.PatientName
开发者ID:scaramallion,项目名称:pydicom,代码行数:10,代码来源:test_charset.py
示例20: test_set_convert_private_elem_from_raw
def test_set_convert_private_elem_from_raw(self):
"""Test Dataset.__setitem__ with a raw private element"""
test_file = get_testdata_files('CT_small.dcm')[0]
ds = dcmread(test_file, force=True)
# 'tag VR length value value_tell is_implicit_VR is_little_endian'
elem = RawDataElement((0x0043, 0x1029), 'OB', 2, b'\x00\x01', 0,
True, True)
ds.__setitem__((0x0043, 0x1029), elem)
assert ds[(0x0043, 0x1029)].value == b'\x00\x01'
assert type(ds[(0x0043, 0x1029)]) == DataElement
开发者ID:moloney,项目名称:pydicom,代码行数:11,代码来源:test_dataset.py
注:本文中的pydicom.dcmread函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论