• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python filereader.read_file函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pydicom.filereader.read_file函数的典型用法代码示例。如果您正苦于以下问题:Python read_file函数的具体用法?Python read_file怎么用?Python read_file使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了read_file函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: setUp

 def setUp(self):
     self.jpeg_ls_lossless = read_file(jpeg_ls_lossless_name)
     self.mr_small = read_file(mr_name)
     self.emri_jpeg_ls_lossless = read_file(emri_jpeg_ls_lossless)
     self.emri_small = read_file(emri_name)
     self.original_handlers = pydicom.config.image_handlers
     pydicom.config.image_handlers = [pillow_handler, numpy_handler]
开发者ID:glemaitre,项目名称:pydicom,代码行数:7,代码来源:test_pillow_pixel_data.py


示例2: test_multivalue_DA

 def test_multivalue_DA(self):
     """Write DA/DT/TM data elements.........."""
     multi_DA_expected = (date(1961, 8, 4), date(1963, 11, 22))
     DA_expected = date(1961, 8, 4)
     tzinfo = tzoffset('-0600', -21600)
     multi_DT_expected = (datetime(1961, 8, 4),
                          datetime(1963, 11, 22, 12, 30, 0, 0,
                                   tzoffset('-0600', -21600)))
     multi_TM_expected = (time(1, 23, 45), time(11, 11, 11))
     TM_expected = time(11, 11, 11, 1)
     ds = read_file(datetime_name)
     # Add date/time data elements
     ds.CalibrationDate = MultiValue(DA, multi_DA_expected)
     ds.DateOfLastCalibration = DA(DA_expected)
     ds.ReferencedDateTime = MultiValue(DT, multi_DT_expected)
     ds.CalibrationTime = MultiValue(TM, multi_TM_expected)
     ds.TimeOfLastCalibration = TM(TM_expected)
     ds.save_as(datetime_out)
     # Now read it back in and check the values are as expected
     ds = read_file(datetime_out)
     self.assertSequenceEqual(multi_DA_expected, ds.CalibrationDate, "Multiple dates not written correctly (VR=DA)")
     self.assertEqual(DA_expected, ds.DateOfLastCalibration, "Date not written correctly (VR=DA)")
     self.assertSequenceEqual(multi_DT_expected, ds.ReferencedDateTime, "Multiple datetimes not written correctly (VR=DT)")
     self.assertSequenceEqual(multi_TM_expected, ds.CalibrationTime, "Multiple times not written correctly (VR=TM)")
     self.assertEqual(TM_expected, ds.TimeOfLastCalibration, "Time not written correctly (VR=DA)")
     if os.path.exists(datetime_out):
         os.remove(datetime_out)  # get rid of the file
开发者ID:Vells,项目名称:pydicom,代码行数:27,代码来源:test_filewriter.py


示例3: testValuesIdentical

 def testValuesIdentical(self):
     """Deferred values exactly matches normal read..............."""
     ds_norm = read_file(self.testfile_name)
     ds_defer = read_file(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:Vells,项目名称:pydicom,代码行数:7,代码来源:test_filereader.py


示例4: setUp

 def setUp(self):
     self.jpeg_2k = read_file(jpeg2000_name)
     self.jpeg_2k_lossless = read_file(jpeg2000_lossless_name)
     self.mr_small = read_file(mr_name)
     self.emri_jpeg_2k_lossless = read_file(emri_jpeg_2k_lossless)
     self.emri_small = read_file(emri_name)
     self.original_handlers = pydicom.config.image_handlers
     pydicom.config.image_handlers = [gdcm_handler]
开发者ID:glemaitre,项目名称:pydicom,代码行数:8,代码来源:test_gdcm_pixel_data.py


示例5: 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
        read_file(priv_SQ_name)
开发者ID:Vells,项目名称:pydicom,代码行数:8,代码来源:test_filereader.py


示例6: testPlanarConfig

 def testPlanarConfig(self):
     px_data_ds = read_file(color_px_name)
     pl_data_ds = read_file(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:Vells,项目名称:pydicom,代码行数:8,代码来源:test_filereader.py


示例7: testwrite_short_uid

 def testwrite_short_uid(self):
     ds = read_file(rtplan_name)
     ds.SOPInstanceUID = "1.2"
     ds.save_as(rtplan_out)
     ds = read_file(rtplan_out)
     ds.save_as(rtplan_out)
     self.assertEqual(ds.SOPInstanceUID, "1.2")
     if os.path.exists(rtplan_out):
         os.remove(rtplan_out)  # get rid of the file
开发者ID:bastula,项目名称:pydicom,代码行数:9,代码来源:test_filewriter.py


示例8: 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 = read_file(ct_name, stop_before_pixels=True)
     ctpartial_tags = sorted(ctpartial.keys())
     ctfull = read_file(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:Vells,项目名称:pydicom,代码行数:11,代码来源:test_filereader.py


示例9: testNestedPrivateSQ

    def testNestedPrivateSQ(self):
        """Can successfully read a private SQ which contains additional SQ's....."""
        # From issue 113. When a private SQ of undefined length is used, the
        #   sequence is read in and the length of the SQ is determined upon
        #   identification of the SQ termination sequence. When using nested
        #   Sequences, the first termination sequence encountered actually
        #   belongs to the nested Sequence not the parent, therefore the
        #   remainder of the file is not read in properly
        ds = read_file(nested_priv_SQ_name)

        # Make sure that the entire dataset was read in
        pixel_data_tag = TupleTag((0x7FE0, 0x10))
        self.assertTrue(pixel_data_tag in ds, "Entire dataset was not parsed properly. PixelData is not present")

        # Check that the DataElement is indeed a Sequence
        tag = TupleTag((0x01, 0x01))
        seq0 = ds[tag]
        self.assertEqual(seq0.VR, "SQ", "First level sequence not parsed properly")

        # Now verify the presence of the nested private SQ
        seq1 = seq0[0][tag]
        self.assertEqual(seq1.VR, "SQ", "Second level sequence not parsed properly")

        # Now make sure the values that are parsed are correct
        got = seq1[0][tag].value
        expected = b"Double Nested SQ"
        self.assertEqual(got, expected, "Expected a value of %s, got %s'" % (expected, got))

        got = seq0[0][0x01, 0x02].value
        expected = b"Nested SQ"
        self.assertEqual(got, expected, "Expected a value of %s, got %s'" % (expected, got))
开发者ID:DimitriPapadopoulos,项目名称:pydicom,代码行数:31,代码来源:test_filereader.py


示例10: testCTPixelData

 def testCTPixelData(self):
     """Check that we can read pixel data. Tests that we get last one in array."""
     ct = read_file(ct_name)
     expected = 909
     got = ct.pixel_array[-1][-1]
     msg = "Did not get correct value for last pixel: expected %d, got %r" % (expected, got)
     self.assertEqual(expected, got, msg)
开发者ID:Vells,项目名称:pydicom,代码行数:7,代码来源:test_filereader.py


示例11: testCT

    def testCT(self):
        """Returns correct values for sample data elements in test CT file...."""
        ct = read_file(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:Vells,项目名称:pydicom,代码行数:25,代码来源:test_filereader.py


示例12: testReadFileGivenFileObject

 def testReadFileGivenFileObject(self):
     """filereader: can read using already opened file............"""
     f = open(ct_name, "rb")
     ct = read_file(f)
     # Tests here simply repeat testCT -- perhaps should collapse the code together?
     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")
     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
     expected = [DS("-158.135803"), DS("-179.035797"), DS("-75.699997")]
     self.assertTrue(got == expected, "ImagePosition(Patient) values not as 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")
     # Should also be able to close the file ourselves without exception raised:
     f.close()
开发者ID:DimitriPapadopoulos,项目名称:pydicom,代码行数:27,代码来源:test_filereader.py


示例13: testDeflate

 def testDeflate(self):
     """Returns correct values for sample data elements in test compressed (zlib deflate) file"""
     # Everything after group 2 is compressed. If we can read anything else, the decompression must have been ok.
     ds = read_file(deflate_name)
     got = ds.ConversionType
     expected = "WSD"
     self.assertEqual(got, expected, "Attempted to read deflated file data element Conversion Type, expected '%s', got '%s'" % (expected, got))
开发者ID:Vells,项目名称:pydicom,代码行数:7,代码来源:test_filereader.py


示例14: testRTstruct

    def testRTstruct(self):
        """Returns correct values for sample elements in test RTSTRUCT file...."""
        # RTSTRUCT test file has complex nested sequences -- see rtstruct.dump file
        # Also has no DICOM header ... so tests 'force' argument of read_file

        rtss = read_file(rtstruct_name, force=True)
        expected = '1.2.840.10008.1.2'  # implVR little endian
        got = rtss.file_meta.TransferSyntaxUID
        msg = "Expected transfer syntax %r, got %r" % (expected, got)
        self.assertEqual(expected, got, msg)
        frame_of_ref = rtss.ReferencedFrameOfReferenceSequence[0]
        study = frame_of_ref.RTReferencedStudySequence[0]
        uid = study.RTReferencedSeriesSequence[0].SeriesInstanceUID
        expected = "1.2.826.0.1.3680043.8.498.2010020400001.2.1.1"
        msg = "Expected Reference Series UID '%s', got '%s'" % (expected, uid)
        self.assertEqual(expected, uid, msg)

        got = rtss.ROIContourSequence[0].ContourSequence[2].ContourNumber
        expected = 3
        msg = "Expected Contour Number %d, got %r" % (expected, got)
        self.assertEqual(expected, got, msg)

        obs_seq0 = rtss.RTROIObservationsSequence[0]
        got = obs_seq0.ROIPhysicalPropertiesSequence[0].ROIPhysicalProperty
        expected = 'REL_ELEC_DENSITY'
        msg = "Expected Physical Property '%s', got %r" % (expected, got)
        self.assertEqual(expected, got, msg)
开发者ID:Vells,项目名称:pydicom,代码行数:27,代码来源:test_filereader.py


示例15: testExplicitVRBigEndianNoMeta

 def testExplicitVRBigEndianNoMeta(self):
     """Read file without file meta with Big Endian Explicit VR dataset......."""
     # Example file from CMS XiO 5.0 and above
     # Still need to force read data since there is no 'DICM' marker present
     ds = read_file(explicit_vr_be_no_meta, force=True)
     got = ds.InstanceCreationDate
     expected = "20150529"
     self.assertEqual(got, expected, "Sample data element from dataset failed, expected '%s', got '%s'" % (expected, got))
开发者ID:Vells,项目名称:pydicom,代码行数:8,代码来源:test_filereader.py


示例16: dump_file

 def dump_file(self, file_path):
     try:
         print('\n' + file_path)
         dataset = filereader.read_file(
             file_path, stop_before_pixels=self.show_image_data, force=True)
         self.print_dataset(dataset)
     except (InvalidDicomError, KeyError):
         print(u'{} is not a valid DICOM file - skipping.'.format(file_path))
开发者ID:mrbean-bremen,项目名称:dcm-spec-tools,代码行数:8,代码来源:dump_dcm_info.py


示例17: testFileExists

    def testFileExists(self):
        """Deferred read raises error if file no longer exists....."""
        ds = read_file(self.testfile_name, defer_size=2000)
        os.remove(self.testfile_name)

        def read_value():
            ds.PixelData

        self.assertRaises(IOError, read_value)
开发者ID:Vells,项目名称:pydicom,代码行数:9,代码来源:test_filereader.py


示例18: testZippedDeferred

 def testZippedDeferred(self):
     """Deferred values from a gzipped file works.............."""
     # Arose from issue 103 "Error for defer_size read of gzip file object"
     fobj = gzip.open(gzip_name)
     ds = read_file(fobj, defer_size=1)
     fobj.close()
     # before the fix, this threw an error as file reading was not in right place,
     #    it was re-opened as a normal file, not zip file
     ds.InstanceNumber
开发者ID:Vells,项目名称:pydicom,代码行数:9,代码来源:test_filereader.py


示例19: testNoMetaGroupLength

 def testNoMetaGroupLength(self):
     """Read file with no group length in file meta..........................."""
     # Issue 108 -- iView example file with no group length (0002,0002)
     # Originally crashed, now check no exception, but also check one item
     #     in file_meta, and second one in followinsg dataset
     ds = read_file(no_meta_group_length)
     got = ds.InstanceCreationDate
     expected = "20111130"
     self.assertEqual(got, expected, "Sample data element after file meta with no group length failed, expected '%s', got '%s'" % (expected, got))
开发者ID:Vells,项目名称:pydicom,代码行数:9,代码来源:test_filereader.py


示例20: testEmptyNumbersTag

 def testEmptyNumbersTag(self):
     """Tests that an empty tag with a number VR (FL, UL, SL, US, SS, FL, FD, OF) reads as an empty string"""
     empty_number_tags_ds = read_file(empty_number_tags_name)
     self.assertEqual(empty_number_tags_ds.ExaminedBodyThickness, "")
     self.assertEqual(empty_number_tags_ds.SimpleFrameList, "")
     self.assertEqual(empty_number_tags_ds.ReferencePixelX0, "")
     self.assertEqual(empty_number_tags_ds.PhysicalUnitsXDirection, "")
     self.assertEqual(empty_number_tags_ds.TagAngleSecondAxis, "")
     self.assertEqual(empty_number_tags_ds.TagSpacingSecondDimension, "")
     self.assertEqual(empty_number_tags_ds.VectorGridData, "")
开发者ID:DimitriPapadopoulos,项目名称:pydicom,代码行数:10,代码来源:test_filereader.py



注:本文中的pydicom.filereader.read_file函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python localdb.LocalDbHandler类代码示例发布时间:2022-05-25
下一篇:
Python filereader.dcmread函数代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap