def test_no_pixel_data_raises(self):
     """Test get_pixeldata raises if dataset has no PixelData."""
     ds = dcmread(MR_RLE_1F)
     del ds.PixelData
     assert 'PixelData' not in ds
     with pytest.raises(AttributeError, match=' dataset: PixelData'):
         get_pixeldata(ds)
Beispiel #2
0
 def test_unknown_pixel_representation_raises(self):
     """Test get_pixeldata raises if invalid PixelRepresentation."""
     ds = dcmread(MR_RLE_1F)
     ds.PixelRepresentation = 2
     # Should probably be ValueError instead
     with pytest.raises(TypeError, match="format='bad_pixel_repr"):
         get_pixeldata(ds)
    def test_little_endian_segment_order(self):
        """Test interpreting segment order as little endian."""
        ds = dcmread(MR_RLE_1F)
        assert ds.file_meta.TransferSyntaxUID == RLELossless
        assert ds.BitsAllocated == 16
        assert ds.SamplesPerPixel == 1
        assert 'NumberOfFrames' not in ds
        assert ds.PixelRepresentation == 1  # signed

        # Big endian
        arr = get_pixeldata(ds, rle_segment_order='>')
        arr = reshape_pixel_array(ds, arr)

        assert (64, 64) == arr.shape
        assert (422, 319, 361) == tuple(arr[0, 31:34])
        assert (366, 363, 322) == tuple(arr[31, :3])
        assert (1369, 1129, 862) == tuple(arr[-1, -3:])

        # Little endian
        arr = get_pixeldata(ds, rle_segment_order='<')
        arr = reshape_pixel_array(ds, arr)

        assert (64, 64) == arr.shape
        assert (-23039, 16129, 26881) == tuple(arr[0, 31:34])
        assert (28161, 27393, 16897) == tuple(arr[31, :3])
        assert (22789, 26884, 24067) == tuple(arr[-1, -3:])
Beispiel #4
0
 def test_no_pixel_data_raises(self):
     """Test get_pixeldata raises if dataset has no PixelData."""
     ds = dcmread(MR_RLE_1F)
     del ds.PixelData
     assert 'PixelData' not in ds
     # Should probably be AttributeError instead
     with pytest.raises(TypeError, match='No pixel data found'):
         get_pixeldata(ds)
Beispiel #5
0
    def test_change_photometric_interpretation(self):
        """Test get_pixeldata changes PhotometricInterpretation if required."""
        def to_rgb(ds):
            """Override the original function that returned False"""
            return True

        # Test default
        ds = dcmread(MR_RLE_1F)
        assert ds.PhotometricInterpretation == 'MONOCHROME2'

        get_pixeldata(ds)
        assert ds.PhotometricInterpretation == 'MONOCHROME2'

        # Test opposite
        orig_fn = RLE_HANDLER.should_change_PhotometricInterpretation_to_RGB
        RLE_HANDLER.should_change_PhotometricInterpretation_to_RGB = to_rgb

        get_pixeldata(ds)
        assert ds.PhotometricInterpretation == 'RGB'

        RLE_HANDLER.should_change_PhotometricInterpretation_to_RGB = orig_fn
Beispiel #6
0
 def time_32bit_1sample(self):
     """Time retrieval of 32-bit, 1 sample/pixel RLE data."""
     for ii in range(self.no_runs):
         get_pixeldata(self.ds_32_1_1)
Beispiel #7
0
 def time_16bit_3sample(self):
     """Time retrieval of 16-bit, 3 sample/pixel RLE data."""
     for ii in range(self.no_runs):
         get_pixeldata(self.ds_16_3_1)
Beispiel #8
0
 def test_unsupported_syntaxes_raises(self):
     """Test get_pixeldata raises if unsupported Transfer Syntax."""
     ds = dcmread(MR_EXPL_LITTLE_1F)
     # Typo in exception message
     with pytest.raises(NotImplementedError, match='RLE decompressordoes'):
         get_pixeldata(ds)
 def test_unsupported_syntaxes_raises(self):
     """Test get_pixeldata raises if unsupported Transfer Syntax."""
     ds = dcmread(MR_EXPL_LITTLE_1F)
     with pytest.raises(NotImplementedError,
                        match='syntax is not supported by the RLE pixel'):
         get_pixeldata(ds)
 def test_unknown_pixel_representation_raises(self):
     """Test get_pixeldata raises if invalid PixelRepresentation."""
     ds = dcmread(MR_RLE_1F)
     ds.PixelRepresentation = 2
     with pytest.raises(ValueError, match=r"value of '2' for '\(0028,0103"):
         get_pixeldata(ds)
 def test_unsupported_syntaxes_raises(self):
     """Test get_pixeldata raises if unsupported Transfer Syntax."""
     ds = dcmread(EXPL_16_1_1F)
     msg = r'syntax is not supported by the RLE pixel'
     with pytest.raises(NotImplementedError, match=msg):
         get_pixeldata(ds)
 def time_16bit_3sample(self):
     """Time retrieval of 16-bit, 3 sample/pixel RLE data."""
     for ii in range(self.no_runs):
         get_pixeldata(self.ds_16_3_1)
 def time_08bit_1sample(self):
     """Time retrieval of 8-bit, 1 sample/pixel RLE data."""
     for ii in range(self.no_runs):
         get_pixeldata(self.ds_8_1_1)