本文整理汇总了Python中pydicom.filereader.dcmread函数的典型用法代码示例。如果您正苦于以下问题:Python dcmread函数的具体用法?Python dcmread怎么用?Python dcmread使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了dcmread函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_big_endian_datasets
def test_big_endian_datasets(self, little, big):
"""Test pixel_array for big endian matches little."""
ds = dcmread(big)
assert ds.file_meta.TransferSyntaxUID == ExplicitVRBigEndian
ref = dcmread(little)
assert ref.file_meta.TransferSyntaxUID != ExplicitVRBigEndian
assert np.array_equal(ds.pixel_array, ref.pixel_array)
示例2: setUp
def setUp(self):
self.jpeg_ls_lossless = dcmread(jpeg_ls_lossless_name)
self.mr_small = dcmread(mr_name)
self.emri_jpeg_ls_lossless = dcmread(emri_jpeg_ls_lossless)
self.emri_small = dcmread(emri_name)
self.original_handlers = pydicom.config.pixel_data_handlers
pydicom.config.pixel_data_handlers = [numpy_handler]
示例3: setUp
def setUp(self):
self.jpeg_ls_lossless = dcmread(jpeg_ls_lossless_name)
self.mr_small = dcmread(mr_name)
self.emri_jpeg_ls_lossless = dcmread(emri_jpeg_ls_lossless)
self.emri_small = dcmread(emri_name)
self.original_handlers = pydicom.config.image_handlers
pydicom.config.image_handlers = [None]
示例4: testValuesIdentical
def testValuesIdentical(self):
"""Deferred values exactly matches normal read..............."""
ds_norm = dcmread(self.testfile_name)
ds_defer = dcmread(self.testfile_name, defer_size=2000)
for data_elem in ds_norm:
tag = data_elem.tag
self.assertEqual(data_elem.value, ds_defer[tag].value,
"Mismatched value for tag %r" % tag)
示例5: setup
def setup(self):
"""Setup the test datasets."""
self.jpeg_2k = dcmread(jpeg2000_name)
self.jpeg_2k_lossless = dcmread(jpeg2000_lossless_name)
self.emri_jpeg_2k_lossless = dcmread(emri_jpeg_2k_lossless)
self.sc_rgb_jpeg2k_gdcm_KY = dcmread(sc_rgb_jpeg2k_gdcm_KY)
self.original_handlers = pydicom.config.pixel_data_handlers
pydicom.config.pixel_data_handlers = [numpy_handler]
示例6: testPlanarConfig
def testPlanarConfig(self):
px_data_ds = dcmread(color_px_name)
pl_data_ds = dcmread(color_pl_name)
assert px_data_ds.PlanarConfiguration != pl_data_ds.PlanarConfiguration
if have_numpy:
px_data = px_data_ds.pixel_array
pl_data = pl_data_ds.pixel_array
self.assertTrue(numpy.all(px_data == pl_data))
示例7: testPrivateSQ
def testPrivateSQ(self):
"""Can read private undefined length SQ without error."""
# From issues 91, 97, 98. Bug introduced by fast reading, due to
# VR=None in raw data elements, then an undefined length private
# item VR is looked up, and there is no such tag,
# generating an exception
# Simply read the file, in 0.9.5 this generated an exception
dcmread(priv_SQ_name)
示例8: test_read_UC_explicit_little
def test_read_UC_explicit_little(self):
"""Check creation of DataElement from byte data works correctly."""
ds = dcmread(self.fp_ex, force=True)
ref_elem = ds.get(0x00189908)
elem = DataElement(0x00189908, 'UC', ['A', 'B', 'C'])
self.assertEqual(ref_elem, elem)
ds = dcmread(self.fp_ex, force=True)
ref_elem = ds.get(0x00100212)
elem = DataElement(0x00100212, 'UC', 'Test')
self.assertEqual(ref_elem, elem)
示例9: testSpecificTagsWithUnknownLengthTag
def testSpecificTagsWithUnknownLengthTag(self):
"""Returns only tags specified by user."""
unknown_len_tag = Tag(0x7fe0, 0x0010) # Pixel Data
tags = dcmread(emri_jpeg_2k_lossless, specific_tags=[
unknown_len_tag])
tags = sorted(tags.keys())
self.assertEqual([unknown_len_tag], tags)
tags = dcmread(emri_jpeg_2k_lossless, specific_tags=[
'SpecificCharacterSet'])
tags = sorted(tags.keys())
self.assertEqual([Tag(0x08, 0x05)], tags)
示例10: testSpecificTagsWithUnknownLengthSQ
def testSpecificTagsWithUnknownLengthSQ(self):
"""Returns only tags specified by user."""
unknown_len_sq_tag = Tag(0x3f03, 0x1001)
tags = dcmread(priv_SQ_name, specific_tags=[
unknown_len_sq_tag])
tags = sorted(tags.keys())
self.assertEqual([unknown_len_sq_tag], tags)
tags = dcmread(priv_SQ_name, specific_tags=[
'PatientName'])
tags = sorted(tags.keys())
self.assertEqual([], tags)
示例11: test_correct_ambiguous_vr_compressed
def test_correct_ambiguous_vr_compressed(self):
"""Test correcting compressed Pixel Data read from file"""
# Create an implicit VR compressed dataset
ds = dcmread(jpeg_lossless_name)
fp = BytesIO()
file_ds = FileDataset(fp, ds)
file_ds.is_implicit_VR = True
file_ds.is_little_endian = True
file_ds.save_as(fp, write_like_original=True)
ds = dcmread(fp, force=True)
self.assertEqual(ds[0x7fe00010].VR, 'OB')
示例12: test_pixel_array_32bit_un_signed
def test_pixel_array_32bit_un_signed(self):
"""Test pixel_array for 32-bit unsigned -> signed."""
ds = dcmread(EXPL_32_3_1F)
# 0 is unsigned int, 1 is 2's complement
assert ds.PixelRepresentation == 0
ds.PixelRepresentation = 1
arr = ds.pixel_array
ref = dcmread(EXPL_32_3_1F)
assert not np.array_equal(arr, ref.pixel_array)
assert (100, 100, 3) == arr.shape
assert -1 == arr[0, :, 0].min() == arr[0, :, 0].max()
assert -2139062144 == arr[50, :, 0].min() == arr[50, :, 0].max()
示例13: testNoPixelsRead
def testNoPixelsRead(self):
"""Returns all data elements before pixels using
stop_before_pixels=False.
"""
# Just check the tags, and a couple of values
ctpartial = dcmread(ct_name, stop_before_pixels=True)
ctpartial_tags = sorted(ctpartial.keys())
ctfull = dcmread(ct_name)
ctfull_tags = sorted(ctfull.keys())
msg = ("Tag list of partial CT read (except pixel tag and padding) "
"did not match full read")
msg += "\nExpected: %r\nGot %r" % (ctfull_tags[:-2], ctpartial_tags)
missing = [Tag(0x7fe0, 0x10), Tag(0xfffc, 0xfffc)]
self.assertEqual(ctfull_tags, ctpartial_tags + missing, msg)
示例14: test_pixel_array_8bit_un_signed
def test_pixel_array_8bit_un_signed(self):
"""Test pixel_array for 8-bit unsigned -> signed data."""
ds = dcmread(EXPL_8_1_1F)
# 0 is unsigned int, 1 is 2's complement
assert ds.PixelRepresentation == 0
ds.PixelRepresentation = 1
arr = ds.pixel_array
ref = dcmread(EXPL_8_1_1F)
assert not np.array_equal(arr, ref.pixel_array)
assert (600, 800) == arr.shape
assert -12 == arr[0].min() == arr[0].max()
assert (1, -10, 1) == tuple(arr[300, 491:494])
assert 0 == arr[-1].min() == arr[-1].max()
示例15: testCT
def testCT(self):
"""Returns correct values for sample data elements in test CT file."""
ct = dcmread(ct_name)
self.assertEqual(ct.file_meta.ImplementationClassUID,
'1.3.6.1.4.1.5962.2',
"ImplementationClassUID not the expected value")
self.assertEqual(ct.file_meta.ImplementationClassUID,
ct.file_meta[0x2, 0x12].value,
"ImplementationClassUID does not match the value "
"accessed by tag number")
# (0020, 0032) Image Position (Patient)
# [-158.13580300000001, -179.035797, -75.699996999999996]
got = ct.ImagePositionPatient
DS = pydicom.valuerep.DS
expected = [DS('-158.135803'), DS('-179.035797'), DS('-75.699997')]
self.assertTrue(got == expected,
"ImagePosition(Patient) values not as expected."
"got {0}, expected {1}".format(got, expected))
self.assertEqual(ct.Rows, 128, "Rows not 128")
self.assertEqual(ct.Columns, 128, "Columns not 128")
self.assertEqual(ct.BitsStored, 16, "Bits Stored not 16")
self.assertEqual(len(ct.PixelData), 128 * 128 * 2,
"Pixel data not expected length")
# Also test private elements name can be resolved:
expected = "[Duration of X-ray on]"
got = ct[(0x0043, 0x104e)].name
msg = "Mismatch in private tag name, expected '%s', got '%s'"
self.assertEqual(expected, got, msg % (expected, got))