def test_encoding_multiple_frames_raises(self): """Test encoding multiple framed pixel data raises exception.""" # Note: only works with multi-sample data ds = dcmread(EXPL_8_3_2F) assert ds.NumberOfFrames > 1 kwargs = RLELosslessEncoder.kwargs_from_ds(ds) msg = ( r"Unable to encode multiple frames at once, please encode one " r"frame at a time" ) with pytest.raises(ValueError, match=msg): rle_encode_frame(ds.pixel_array)
def test_cycle_32bit_1sample(self): """Test an encode/decode cycle for 32-bit 1 sample/pixel.""" ds = dcmread(EXPL_32_1_1F) ref = ds.pixel_array assert 32 == ds.BitsAllocated assert 1 == ds.SamplesPerPixel kwargs = RLELosslessEncoder.kwargs_from_ds(ds) encoded = _encode_frame(ds.PixelData, **kwargs) decoded = _rle_decode_frame( encoded, ds.Rows, ds.Columns, ds.SamplesPerPixel, ds.BitsAllocated ) arr = np.frombuffer(decoded, '<u4') arr = reshape_pixel_array(ds, arr) assert np.array_equal(ref, arr)
def test_cycle_32bit_3sample(self): """Test an encode/decode cycle for 32-bit 3 sample/pixel.""" ds = dcmread(EXPL_32_3_1F) ref = ds.pixel_array assert ds.BitsAllocated == 32 assert ds.SamplesPerPixel == 3 assert ds.PixelRepresentation == 0 kwargs = RLELosslessEncoder.kwargs_from_ds(ds) encoded = _encode_frame(ds.PixelData, **kwargs) decoded = _rle_decode_frame( encoded, ds.Rows, ds.Columns, ds.SamplesPerPixel, ds.BitsAllocated ) # The decoded data is planar configuration 1 ds.PlanarConfiguration = 1 arr = np.frombuffer(decoded, '<u4') arr = reshape_pixel_array(ds, arr) assert np.array_equal(ref, arr)