def test_no_pixel_data_raises(self): """Test get_pixeldata raises if dataset has no PixelData.""" ds = dcmread(EXPL_16_1_1F) del ds.PixelData assert 'PixelData' not in ds with pytest.raises(AttributeError, match=' dataset: PixelData'): get_pixeldata(ds)
def test_unknown_pixel_representation_raises(self): """Test get_pixeldata raises if unsupported PixelRepresentation.""" ds = dcmread(EXPL_16_1_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) ds.file_meta.TransferSyntaxUID = '1.2.840.10008.1.2.4.50' with pytest.raises(NotImplementedError, match=' the transfer syntax is not supported'): get_pixeldata(ds)
def time_1bit_1sample_3frame(self): """Time retrieval of 1-bit, 1 sample/pixel, 3 frame.""" no_runs = self.no_runs if 'PyPy' in python_implementation(): no_runs = 1 for ii in range(no_runs): get_pixeldata(self.ds_1_1_3)
def test_array_read_only_bit_packed(self): """Test returning a read only array for BitsAllocated = 1.""" ds = dcmread(EXPL_1_1_1F) arr = get_pixeldata(ds, read_only=False) assert arr.flags.writeable arr = get_pixeldata(ds, read_only=True) assert arr.flags.writeable
def test_bad_length_raises(self): """Test bad pixel data length raises exception.""" ds = dcmread(EXPL_8_1_1F) # Too short ds.PixelData = ds.PixelData[:-1] msg = ( r"The length of the pixel data in the dataset doesn't match the " r"expected amount \(479999 vs. 480000 bytes\). The dataset may be " r"corrupted or there may be an issue with the pixel data handler." ) with pytest.raises(ValueError, match=msg): get_pixeldata(ds)
def test_array_read_only(self): """Test returning a read only array for BitsAllocated > 8.""" ds = dcmread(EXPL_8_1_1F) arr = get_pixeldata(ds, read_only=False) assert arr.flags.writeable assert 0 != arr[10] arr[10] = 0 assert 0 == arr[10] arr = get_pixeldata(ds, read_only=True) assert not arr.flags.writeable with pytest.raises(ValueError, match="is read-only"): arr[10] = 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(EXPL_16_1_1F) assert ds.PhotometricInterpretation == 'MONOCHROME2' get_pixeldata(ds) assert ds.PhotometricInterpretation == 'MONOCHROME2' # Test modified orig_fn = NP_HANDLER.should_change_PhotometricInterpretation_to_RGB NP_HANDLER.should_change_PhotometricInterpretation_to_RGB = to_rgb get_pixeldata(ds) assert ds.PhotometricInterpretation == 'RGB' NP_HANDLER.should_change_PhotometricInterpretation_to_RGB = orig_fn
def time_1bit_1sample_3frame(self): """Time retrieval of 1-bit, 1 sample/pixel, 3 frame.""" # Slow! for ii in range(1): get_pixeldata(self.ds_1_1_3)
def time_large_dataset(self): """Time reading pixel data from a large dataset.""" for ii in range(self.no_runs): get_pixeldata(self.ds_16_3_100)
def time_32bit_3sample_2frame(self): """Time retrieval of 32-bit, 3 sample/pixel, 2 frame.""" for ii in range(self.no_runs): get_pixeldata(self.ds_32_3_2)
def time_32bit_1sample_15frame(self): """Time retrieval of 32-bit, 1 sample/pixel, 15 frame.""" for ii in range(self.no_runs): get_pixeldata(self.ds_32_1_15)
def time_16bit_3sample_1frame(self): """Time retrieval of 16-bit, 3 sample/pixel, 1 frame.""" for ii in range(self.no_runs): get_pixeldata(self.ds_16_3_1)
def time_16bit_3sample_2frame(self): """Time retrieval of 16-bit, 3 sample/pixel, 2 frame.""" for ii in range(self.no_runs): get_pixeldata(self.ds_16_3_2)
def time_16bit_1sample_10frame(self): """Time retrieval of 16-bit, 1 sample/pixel, 10 frame.""" for ii in range(self.no_runs): get_pixeldata(self.ds_16_1_10)
def time_8bit_3sample_1frame(self): """Time retrieval of 8-bit, 3 sample/pixel, 1 frame.""" for ii in range(self.no_runs): get_pixeldata(self.ds_8_3_1)
def time_8bit_1sample_2frame(self): """Time retrieval of 8-bit, 1 sample/pixel, 2 frame.""" for ii in range(self.no_runs): get_pixeldata(self.ds_8_1_2)
def time_ybr_422(self): """Time retrieval of YBR_FULL_422 data.""" for ii in range(self.no_runs): get_pixeldata(self.ds_ybr_422)