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

Python filebase.DicomBytesIO类代码示例

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

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



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

示例1: test_deferred_data_element_deprecated

def test_deferred_data_element_deprecated():
    """Test the deprecation warning is working"""
    fp = DicomBytesIO()
    fp.is_little_endian = True
    fp.is_implicit_VR = True
    with pytest.deprecated_call():
        elem = DeferredDataElement(0x00000000, 'UL', fp, 0, 0, 4)
开发者ID:kayarre,项目名称:pydicom,代码行数:7,代码来源:test_dataelem.py


示例2: test_read_be_tag

 def test_read_be_tag(self):
     """Test DicomIO.read_be_tag indirectly"""
     # Tags are 2 + 2 = 4 bytes
     bytestream = b'\x01\x02\x03\x04\x05\x06'
     fp = DicomBytesIO(bytestream)
     fp.is_little_endian = False
     assert Tag(fp.read_be_tag()) == 0x01020304
开发者ID:jrkerns,项目名称:pydicom,代码行数:7,代码来源:test_filebase.py


示例3: 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


示例4: test_zero_length

 def test_zero_length(self):
     """Test reading BOT with zero length"""
     bytestream = b'\xFE\xFF\x00\xE0' \
                  b'\x00\x00\x00\x00'
     fp = DicomBytesIO(bytestream)
     fp.is_little_endian = True
     assert [0] == get_frame_offsets(fp)
开发者ID:kayarre,项目名称:pydicom,代码行数:7,代码来源:test_encaps.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: test_single_frame

 def test_single_frame(self):
     """Test reading single-frame BOT item"""
     bytestream = b'\xFE\xFF\x00\xE0' \
                  b'\x04\x00\x00\x00' \
                  b'\x00\x00\x00\x00'
     fp = DicomBytesIO(bytestream)
     fp.is_little_endian = True
     assert [0] == get_frame_offsets(fp)
开发者ID:kayarre,项目名称:pydicom,代码行数:8,代码来源:test_encaps.py


示例7: encode

def encode(ds, is_implicit_VR, is_little_endian):
    f = DicomBytesIO()
    f.is_implicit_VR = is_implicit_VR
    f.is_little_endian = is_little_endian
    write_dataset(f, ds)
    rawstr = f.parent.getvalue()
    f.close()
    return rawstr
开发者ID:efflicto,项目名称:pynetdicom,代码行数:8,代码来源:dsutils.py


示例8: test_single_fragment_no_delimiter

 def test_single_fragment_no_delimiter(self):
     """Test single fragment is returned OK"""
     bytestream = b'\xFE\xFF\x00\xE0' \
                  b'\x04\x00\x00\x00' \
                  b'\x01\x00\x00\x00'
     fp = DicomBytesIO(bytestream)
     fp.is_little_endian = True
     assert read_item(fp) == b'\x01\x00\x00\x00'
开发者ID:kayarre,项目名称:pydicom,代码行数:8,代码来源:test_encaps.py


示例9: encode_element

def encode_element(el, is_implicit_VR, is_little_endian):
    f = DicomBytesIO()
    f.is_implicit_VR = is_implicit_VR
    f.is_little_endian = is_little_endian
    write_data_element(f, el)
    rawstr = f.parent.getvalue()
    f.close()
    return rawstr
开发者ID:scaramallion,项目名称:pynetdicom,代码行数:8,代码来源:dsutils.py


示例10: test_read_exact_length_raises

 def test_read_exact_length_raises(self):
     """Test DicomIO.read exact length raises if short"""
     fp = DicomBytesIO(b'\x00\x01\x03')
     fp.is_little_endian = True
     with pytest.raises(EOFError,
                        match="Unexpected end of file. Read 3 bytes of 4 "
                              "expected starting at position 0x0"):
         fp.read(length=4, need_exact_length=True)
开发者ID:jrkerns,项目名称:pydicom,代码行数:8,代码来源:test_filebase.py


示例11: test_read_le_ul

 def test_read_le_ul(self):
     """Test DicomIO.read_leUL indirectly"""
     # UL are 4 bytes fixed
     bytestream = b'\x00\x00\x00\x00\xFF\xFF\x00\x00\xFE\xFF\xFF\xFF'
     fp = DicomBytesIO(bytestream)
     fp.is_little_endian = True
     assert fp.read_leUL() == 0
     assert fp.read_leUL() == 0xFFFF
     assert fp.read_leUL() == 0xFFFFFFFE
开发者ID:jrkerns,项目名称:pydicom,代码行数:9,代码来源:test_filebase.py


示例12: test_read_be_us

 def test_read_be_us(self):
     """Test DicomIO.read_beUS indirectly"""
     # US are 2 bytes fixed
     bytestream = b'\x00\x00\x00\xFF\xFF\xFE'
     fp = DicomBytesIO(bytestream)
     fp.is_little_endian = True
     assert fp.read_beUS() == 0
     assert fp.read_beUS() == 255
     assert fp.read_beUS() == 0xFFFE
开发者ID:jrkerns,项目名称:pydicom,代码行数:9,代码来源:test_filebase.py


示例13: test_not_little_endian

 def test_not_little_endian(self):
     """Test reading big endian raises exception"""
     bytestream = b'\xFE\xFF\x00\xE0' \
                  b'\x00\x00\x00\x00'
     fp = DicomBytesIO(bytestream)
     fp.is_little_endian = False
     with pytest.raises(ValueError,
                        match="'fp.is_little_endian' must be True"):
         get_frame_offsets(fp)
开发者ID:kayarre,项目名称:pydicom,代码行数:9,代码来源:test_encaps.py


示例14: test_multi_frame

 def test_multi_frame(self):
     """Test reading multi-frame BOT item"""
     bytestream = b'\xFE\xFF\x00\xE0' \
                  b'\x10\x00\x00\x00' \
                  b'\x00\x00\x00\x00' \
                  b'\x66\x13\x00\x00' \
                  b'\xF4\x25\x00\x00' \
                  b'\xFE\x37\x00\x00'
     fp = DicomBytesIO(bytestream)
     fp.is_little_endian = True
     assert [0, 4966, 9716, 14334] == get_frame_offsets(fp)
开发者ID:kayarre,项目名称:pydicom,代码行数:11,代码来源:test_encaps.py


示例15: test_item_undefined_length

 def test_item_undefined_length(self):
     """Test exception raised if item length undefined."""
     bytestream = b'\xFE\xFF\x00\xE0' \
                  b'\xFF\xFF\xFF\xFF' \
                  b'\x00\x00\x00\x01'
     fp = DicomBytesIO(bytestream)
     fp.is_little_endian = True
     with pytest.raises(ValueError,
                        match="Encapsulated data fragment had Undefined "
                              "Length at data position 0x4"):
         read_item(fp)
开发者ID:kayarre,项目名称:pydicom,代码行数:11,代码来源:test_encaps.py


示例16: test_bad_tag

 def test_bad_tag(self):
     """Test raises exception if no item tag."""
     # (fffe,e100)
     bytestream = b'\xFE\xFF\x00\xE1' \
                  b'\x08\x00\x00\x00' \
                  b'\x01\x02\x03\x04\x05\x06\x07\x08'
     fp = DicomBytesIO(bytestream)
     fp.is_little_endian = True
     with pytest.raises(ValueError,
                        match="Unexpected tag '\(fffe, e100\)' when "
                              "parsing the Basic Table Offset item."):
         get_frame_offsets(fp)
开发者ID:kayarre,项目名称:pydicom,代码行数:12,代码来源:test_encaps.py


示例17: 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


示例18: test_bad_length_multiple

 def test_bad_length_multiple(self):
     """Test raises exception if the item length is not a multiple of 4."""
     # Length 10
     bytestream = b'\xFE\xFF\x00\xE0' \
                  b'\x0A\x00\x00\x00' \
                  b'\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A'
     fp = DicomBytesIO(bytestream)
     fp.is_little_endian = True
     with pytest.raises(ValueError,
                        match="The length of the Basic Offset Table item"
                              " is not a multiple of 4."):
         get_frame_offsets(fp)
开发者ID:kayarre,项目名称:pydicom,代码行数:12,代码来源:test_encaps.py


示例19: test_multi_fragments_no_delimiter

 def test_multi_fragments_no_delimiter(self):
     """Test multi fragments are returned OK"""
     bytestream = b'\xFE\xFF\x00\xE0' \
                  b'\x04\x00\x00\x00' \
                  b'\x01\x00\x00\x00' \
                  b'\xFE\xFF\x00\xE0' \
                  b'\x06\x00\x00\x00' \
                  b'\x01\x02\x03\x04\x05\x06'
     fp = DicomBytesIO(bytestream)
     fp.is_little_endian = True
     assert read_item(fp) == b'\x01\x00\x00\x00'
     assert read_item(fp) == b'\x01\x02\x03\x04\x05\x06'
开发者ID:kayarre,项目名称:pydicom,代码行数:12,代码来源:test_encaps.py


示例20: test_write_tag

    def test_write_tag(self):
        """Test DicomIO.write_tag indirectly"""
        tag = Tag(0x01020304)

        # Little endian
        fp = DicomBytesIO()
        fp.is_little_endian = True
        fp.write_tag(tag)
        assert fp.getvalue() == b'\x02\x01\x04\x03'

        # Big endian
        fp = DicomBytesIO()
        fp.is_little_endian = False
        fp.write_tag(tag)
        assert fp.getvalue() == b'\x01\x02\x03\x04'
开发者ID:jrkerns,项目名称:pydicom,代码行数:15,代码来源:test_filebase.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python filereader.dcmread函数代码示例发布时间:2022-05-25
下一篇:
Python dataset.Dataset类代码示例发布时间: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