本文整理汇总了Python中pydicom.filereader.dcmread函数的典型用法代码示例。如果您正苦于以下问题:Python dcmread函数的具体用法?Python dcmread怎么用?Python dcmread使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了dcmread函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:darcymason,项目名称:pydicom,代码行数:7,代码来源:test_numpy_pixel_data.py
示例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]
开发者ID:darcymason,项目名称:pydicom,代码行数:7,代码来源:test_jpeg_ls_pixel_data.py
示例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]
开发者ID:jrkerns,项目名称:pydicom,代码行数:7,代码来源:test_numpy_pixel_data.py
示例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)
开发者ID:kayarre,项目名称:pydicom,代码行数:8,代码来源:test_filereader.py
示例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]
开发者ID:darcymason,项目名称:pydicom,代码行数:8,代码来源:test_pillow_pixel_data.py
示例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))
开发者ID:kayarre,项目名称:pydicom,代码行数:8,代码来源:test_filereader.py
示例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)
开发者ID:kayarre,项目名称:pydicom,代码行数:9,代码来源:test_filereader.py
示例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)
开发者ID:kayarre,项目名称:pydicom,代码行数:11,代码来源:test_filereader.py
示例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)
开发者ID:kayarre,项目名称:pydicom,代码行数:12,代码来源:test_filereader.py
示例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)
开发者ID:kayarre,项目名称:pydicom,代码行数:12,代码来源:test_filereader.py
示例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')
开发者ID:kayarre,项目名称:pydicom,代码行数:12,代码来源:test_filereader.py
示例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()
开发者ID:darcymason,项目名称:pydicom,代码行数:13,代码来源:test_numpy_pixel_data.py
示例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)
开发者ID:kayarre,项目名称:pydicom,代码行数:14,代码来源:test_filereader.py
示例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()
开发者ID:darcymason,项目名称:pydicom,代码行数:14,代码来源:test_numpy_pixel_data.py
示例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))
开发者ID:kayarre,项目名称:pydicom,代码行数:30,代码来源:test_filereader.py
示例16: testRTPlan
def testRTPlan(self):
"""Returns correct values for sample data elements in test
RT Plan file.
"""
plan = dcmread(rtplan_name)
beam = plan.BeamSequence[0]
# if not two controlpoints, then this would raise exception
cp0, cp1 = beam.ControlPointSequence
self.assertEqual(beam.TreatmentMachineName, "unit001",
"Incorrect unit name")
self.assertEqual(beam.TreatmentMachineName, beam[0x300a, 0x00b2].value,
"beam TreatmentMachineName does not match "
"the value accessed by tag number")
got = cp1.ReferencedDoseReferenceSequence[
0].CumulativeDoseReferenceCoefficient
DS = pydicom.valuerep.DS
expected = DS('0.9990268')
self.assertTrue(got == expected,
"Cum Dose Ref Coeff not the expected value "
"(CP1, Ref'd Dose Ref")
got = cp0.BeamLimitingDevicePositionSequence[0].LeafJawPositions
self.assertTrue(got[0] == DS('-100') and got[1] == DS('100.0'),
"X jaws not as expected (control point 0)")
开发者ID:kayarre,项目名称:pydicom,代码行数:25,代码来源:test_filereader.py
示例17: test_PI_RGB
def test_PI_RGB(test_with_pillow,
image,
PhotometricInterpretation,
results,
ground_truth):
t = dcmread(image)
assert t.PhotometricInterpretation == PhotometricInterpretation
a = t.pixel_array
assert a.shape == (100, 100, 3)
"""
This complete test never gave a different result than
just the 10 point test below
gt = dcmread(ground_truth)
b = gt.pixel_array
for x in range(100):
for y in range(100):
assert tuple(a[x, y]) == tuple(b[x, y])
"""
# this test points are from the ImageComments tag
assert tuple(a[5, 50, :]) == results[0]
assert tuple(a[15, 50, :]) == results[1]
assert tuple(a[25, 50, :]) == results[2]
assert tuple(a[35, 50, :]) == results[3]
assert tuple(a[45, 50, :]) == results[4]
assert tuple(a[55, 50, :]) == results[5]
assert tuple(a[65, 50, :]) == results[6]
assert tuple(a[75, 50, :]) == results[7]
assert tuple(a[85, 50, :]) == results[8]
assert tuple(a[95, 50, :]) == results[9]
assert t.PhotometricInterpretation == PhotometricInterpretation
开发者ID:kayarre,项目名称:pydicom,代码行数:31,代码来源:test_pillow_pixel_data.py
示例18: test_unknown_pixel_representation_raises
def test_unknown_pixel_representation_raises(self):
"""Test get_pixeldata raises if unsupported PixelRepresentation."""
ds = dcmread(EXPL_16_1_1F)
ds.PixelRepresentation = 2
with pytest.raises(ValueError,
match=r"value of '2' for '\(0028,0103"):
get_pixeldata(ds)
开发者ID:darcymason,项目名称:pydicom,代码行数:7,代码来源:test_numpy_pixel_data.py
示例19: test_empty_file
def test_empty_file(self):
"""Test reading no elements from file produces empty Dataset"""
with tempfile.NamedTemporaryFile() as f:
ds = dcmread(f, force=True)
self.assertTrue(ds.preamble is None)
self.assertEqual(ds.file_meta, Dataset())
self.assertEqual(ds[:], Dataset())
开发者ID:darcymason,项目名称:pydicom,代码行数:7,代码来源:test_filereader.py
示例20: test_little_32bit_3sample_2frame
def test_little_32bit_3sample_2frame(self):
"""Test pixel_array for little 32-bit, 3 sample/pixel, 10 frame."""
# Check all little endian syntaxes
ds = dcmread(EXPL_32_3_2F)
for uid in SUPPORTED_SYNTAXES[:3]:
ds.file_meta.TransferSyntaxUID = uid
arr = ds.pixel_array
assert arr.flags.writeable
# Frame 1
assert (4294967295, 0, 0) == tuple(arr[0, 5, 50, :])
assert (4294967295, 2155905152, 2155905152) == tuple(
arr[0, 15, 50, :]
)
assert (0, 4294967295, 0) == tuple(arr[0, 25, 50, :])
assert (2155905152, 4294967295, 2155905152) == tuple(
arr[0, 35, 50, :]
)
assert (0, 0, 4294967295) == tuple(arr[0, 45, 50, :])
assert (2155905152, 2155905152, 4294967295) == tuple(
arr[0, 55, 50, :]
)
assert (0, 0, 0) == tuple(arr[0, 65, 50, :])
assert (1077952576, 1077952576, 1077952576) == tuple(
arr[0, 75, 50, :]
)
assert (3233857728, 3233857728, 3233857728) == tuple(
arr[0, 85, 50, :]
)
assert (4294967295, 4294967295, 4294967295) == tuple(
arr[0, 95, 50, :]
)
# Frame 2 is frame 1 inverted
assert np.array_equal((2**ds.BitsAllocated - 1) - arr[1], arr[0])
开发者ID:darcymason,项目名称:pydicom,代码行数:35,代码来源:test_numpy_pixel_data.py
注:本文中的pydicom.filereader.dcmread函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论