当前位置: 首页>>代码示例>>Python>>正文


Python Dataset.PixelData方法代码示例

本文整理汇总了Python中pydicom.dataset.Dataset.PixelData方法的典型用法代码示例。如果您正苦于以下问题:Python Dataset.PixelData方法的具体用法?Python Dataset.PixelData怎么用?Python Dataset.PixelData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pydicom.dataset.Dataset的用法示例。


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

示例1: test_pixel_data

# 需要导入模块: from pydicom.dataset import Dataset [as 别名]
# 或者: from pydicom.dataset.Dataset import PixelData [as 别名]
    def test_pixel_data(self):
        """Test correcting PixelData."""
        ref_ds = Dataset()

        # If BitsAllocated  > 8 then VR must be OW
        ref_ds.BitsAllocated = 16
        ref_ds.PixelData = b'\x00\x01' # Little endian 256
        ds = correct_ambiguous_vr(deepcopy(ref_ds), True) # Little endian
        self.assertEqual(ds.PixelData, b'\x00\x01')
        self.assertEqual(ds[0x7fe00010].VR, 'OW')
        ds = correct_ambiguous_vr(deepcopy(ref_ds), False) # Big endian
        self.assertEqual(ds.PixelData, b'\x00\x01')
        self.assertEqual(ds[0x7fe00010].VR, 'OW')

        # If BitsAllocated <= 8 then VR can be OB or OW: OW
        ref_ds = Dataset()
        ref_ds.BitsAllocated = 8
        ref_ds.Rows = 2
        ref_ds.Columns = 2
        ref_ds.PixelData = b'\x01\x00\x02\x00\x03\x00\x04\x00'
        ds = correct_ambiguous_vr(deepcopy(ref_ds), True)
        self.assertEqual(ds.PixelData, b'\x01\x00\x02\x00\x03\x00\x04\x00')
        self.assertEqual(ds[0x7fe00010].VR, 'OW')

        # If BitsAllocated <= 8 then VR can be OB or OW: OB
        ref_ds = Dataset()
        ref_ds.BitsAllocated = 8
        ref_ds.Rows = 2
        ref_ds.Columns = 2
        ref_ds.PixelData = b'\x01\x02\x03\x04'
        ds = correct_ambiguous_vr(deepcopy(ref_ds), True)
        self.assertEqual(ds.PixelData, b'\x01\x02\x03\x04')
        self.assertEqual(ds[0x7fe00010].VR, 'OB')

        # If no BitsAllocated then VR should be unchanged
        ref_ds = Dataset()
        ref_ds.PixelData = b'\x00\x01' # Big endian 1
        ds = correct_ambiguous_vr(deepcopy(ref_ds), True)
        self.assertEqual(ds.PixelData, b'\x00\x01')
        self.assertEqual(ds[0x7fe00010].VR, 'OB or OW')

        # If required elements missing then VR should be unchanged
        ref_ds = Dataset()
        ref_ds.BitsAllocated = 8
        ref_ds.Rows = 2
        ref_ds.PixelData = b'\x01\x02\x03\x04'
        ds = correct_ambiguous_vr(deepcopy(ref_ds), True)
        self.assertEqual(ds.PixelData, b'\x01\x02\x03\x04')
        self.assertEqual(ds[0x7fe00010].VR, 'OB or OW')
开发者ID:bastula,项目名称:pydicom,代码行数:51,代码来源:test_filewriter.py

示例2: test_get_pixel_array_already_have

# 需要导入模块: from pydicom.dataset import Dataset [as 别名]
# 或者: from pydicom.dataset.Dataset import PixelData [as 别名]
 def test_get_pixel_array_already_have(self):
     """Test Dataset._get_pixel_array when we already have the array"""
     # Test that _pixel_array is returned unchanged unless required
     ds = Dataset()
     ds.PixelData = b'\x00'
     ds._pixel_id = id(ds.PixelData)
     ds._pixel_array = 'Test Value'
     assert ds._get_pixel_array() == 'Test Value'
开发者ID:moloney,项目名称:pydicom,代码行数:10,代码来源:test_dataset.py

示例3: test_endianness_not_set

# 需要导入模块: from pydicom.dataset import Dataset [as 别名]
# 或者: from pydicom.dataset.Dataset import PixelData [as 别名]
    def test_endianness_not_set(self):
        """Test for #704, Dataset.is_little_endian unset."""
        ds = Dataset()
        ds.file_meta = Dataset()
        ds.file_meta.TransferSyntaxUID = ExplicitVRLittleEndian
        ds.Rows = 10
        ds.Columns = 10
        ds.BitsAllocated = 16
        ds.PixelRepresentation = 0
        ds.SamplesPerPixel = 1
        arr = np.ones((10, 10), dtype='uint16')
        ds.PixelData = arr.tobytes()

        assert ds.pixel_array.max() == 1
开发者ID:darcymason,项目名称:pydicom,代码行数:16,代码来源:test_numpy_pixel_data.py

示例4: testAttributeErrorInProperty

# 需要导入模块: from pydicom.dataset import Dataset [as 别名]
# 或者: from pydicom.dataset.Dataset import PixelData [as 别名]
    def testAttributeErrorInProperty(self):
        """Dataset: AttributeError in property raises actual error message.."""
        # This comes from bug fix for issue 42
        # First, fake enough to try the pixel_array property
        ds = Dataset()
        ds.file_meta = Dataset()
        ds.PixelData = 'xyzlmnop'

        def callable_pixel_array():
            ds.pixel_array

        msg = "AttributeError in pixel_array property: " + \
            "'Dataset' object has no attribute 'TransferSyntaxUID'"
        self.failUnlessExceptionArgs(msg, PropertyError, callable_pixel_array)
开发者ID:bastula,项目名称:pydicom,代码行数:16,代码来源:test_dataset.py

示例5: testAttributeErrorInProperty

# 需要导入模块: from pydicom.dataset import Dataset [as 别名]
# 或者: from pydicom.dataset.Dataset import PixelData [as 别名]
    def testAttributeErrorInProperty(self):
        """Dataset: AttributeError in property raises actual error message.."""
        # This comes from bug fix for issue 42
        # First, fake enough to try the pixel_array property
        ds = Dataset()
        ds.file_meta = Dataset()
        ds.PixelData = "xyzlmnop"

        def callable_pixel_array():
            ds.pixel_array

        attribute_error_msg = (
            "AttributeError in pixel_array property: " + "Dataset does not have attribute 'TransferSyntaxUID'"
        )
        self.failUnlessExceptionArgs(attribute_error_msg, PropertyError, callable_pixel_array)
开发者ID:DimitriPapadopoulos,项目名称:pydicom,代码行数:17,代码来源:test_dataset.py

示例6: testAttributeErrorInProperty

# 需要导入模块: from pydicom.dataset import Dataset [as 别名]
# 或者: from pydicom.dataset.Dataset import PixelData [as 别名]
 def testAttributeErrorInProperty(self):
     """Dataset: AttributeError in property raises actual error message.."""
     # This comes from bug fix for issue 42
     # First, fake enough to try the pixel_array property
     ds = Dataset()
     ds.file_meta = Dataset()
     ds.PixelData = 'xyzlmnop'
     msg_from_gdcm = r"'Dataset' object has no attribute 'filename'"
     msg_from_numpy = (r"'Dataset' object has no attribute "
                       "'TransferSyntaxUID'")
     msg_from_pillow = (r"'Dataset' object has no attribute "
                        "'PixelRepresentation'")
     msg = "(" + "|".join(
         [msg_from_gdcm, msg_from_numpy, msg_from_pillow]) + ")"
     with self.assertRaisesRegexp(AttributeError, msg):
         ds.pixel_array
开发者ID:moloney,项目名称:pydicom,代码行数:18,代码来源:test_dataset.py

示例7: _create_temporary_dataset

# 需要导入模块: from pydicom.dataset import Dataset [as 别名]
# 或者: from pydicom.dataset.Dataset import PixelData [as 别名]
def _create_temporary_dataset(shape=(100, 1024, 1024, 3), bit_depth=16):
    """Function to create a temporary dataset for use in testing.

    Parameters
    ----------
    shape : 4-tuple
        The (frames, rows, columns, channels) of the test dataset.
    bit_depth : int
        The BitsAllocated value to use for the dataset, one of 8, 16, 32, 64.

    Returns
    -------
    tempfile.TemporaryFile
        A created DICOM File Format conformant dataset.
    """
    ds = Dataset()
    ds.is_little_endian = True
    ds.is_implicit_VR = False
    ds.file_meta = Dataset()
    ds.file_meta.TransferSyntaxUID = ExplicitVRLittleEndian
    ds.SOPClassUID = '1.2.3.4'
    ds.SOPInstanceUID = generate_uid()
    ds.BitsAllocated = bit_depth
    ds.PixelRepresentation = 0
    ds.PlanarConfiguration = 0
    ds.Rows = shape[1]
    ds.Columns = shape[2]
    ds.NumberOfFrames = shape[0]
    ds.SamplesPerPixel = shape[3]
    if shape[3] == 1:
        ds.PhotometricInterpretation = 'MONOCHROME2'
    elif shape[3] == 3:
        ds.PhotometricInterpretation = 'RGB'

    arr = np.zeros(shape, dtype='uint{}'.format(bit_depth))
    ds.PixelData = arr.tobytes()

    if len(ds.PixelData) % 2:
        ds.PixelData += b'\x00'

    tfile = TemporaryFile(mode='w+b')
    ds.save_as(tfile, write_like_original=False)
    tfile.seek(0)

    return tfile
开发者ID:darcymason,项目名称:pydicom,代码行数:47,代码来源:bench_handler_numpy.py


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