def test_invalid_colourspace_warns(): """Test that using an unknown colourspace gives a warning.""" index = get_indexed_datasets('1.2.840.10008.1.2.4.50') ds = index['JPEGBaseline_1s_1f_u_08_08.dcm']['ds'] nr_frames = ds.get('NumberOfFrames', 1) frame = next(generate_pixel_data_frame(ds.PixelData, nr_frames)) msg = r"no colour transformation will be applied" ds.PhotometricInterpretation = 'ANY' with pytest.warns(UserWarning, match=msg): arr = decode_pixel_data(np.frombuffer(frame, 'uint8'), ds) arr = reshape_pixel_array(ds, arr) assert arr.flags.writeable assert 'uint8' == arr.dtype assert (ds.Rows, ds.Columns) == arr.shape # Reference values from GDCM handler assert 76 == arr[5, 50] assert 167 == arr[15, 50] assert 149 == arr[25, 50] assert 203 == arr[35, 50] assert 29 == arr[45, 50] assert 142 == arr[55, 50] assert 1 == arr[65, 50] assert 64 == arr[75, 50] assert 192 == arr[85, 50] assert 255 == arr[95, 50]
def test_invalid_colour_transform(self): """Test that an invalid colour transform raises an exception.""" ds_list = get_indexed_datasets('1.2.840.10008.1.2.4.50') # Image has invalid Se value in the SOS marker segment ds = ds_list['color3d_jpeg_baseline.dcm']['ds'] data = defragment_data(ds.PixelData) msg = (r"Unknown error code '-8194' returned from Decode\(\): " r"Invalid colourTransform value") with pytest.raises(RuntimeError, match=msg): decode(np.frombuffer(data, 'uint8'), -1)
def test_non_conformant_raises(self): """Test that a non-conformant JPEG image raises an exception.""" ds_list = get_indexed_datasets('1.2.840.10008.1.2.4.51') # Image has invalid Se value in the SOS marker segment item = ds_list['JPEG-lossy.dcm'] assert 0xC000 == item['Status'][1] msg = (r"libjpeg error code '-1038' returned from Decode\(\): A " r"misplaced marker segment was found - scan start must be zero " r"and scan stop must be 63 for the sequential operating modes") with pytest.raises(RuntimeError, match=msg): item['ds'].pixel_array
def test_extended(self, fname, info): """Test get_parameters() for the LS lossy datasets.""" #info: (rows, columns, spp, bps) index = get_indexed_datasets('1.2.840.10008.1.2.4.81') ds = index[fname]['ds'] frame = next(self.generate_frames(ds)) params = get_parameters(np.frombuffer(frame, 'uint8')) assert (info[0], info[1]) == (params['rows'], params['columns']) assert info[2] == params["nr_components"] assert info[3] == params["precision"]
def test_non_conformant_raises(): """Test that a non-conformant JPEG image raises an exception.""" ds_list = get_indexed_datasets('1.2.840.10008.1.2.4.51') # Image has invalid Se value in the SOS marker segment item = ds_list['JPEG-lossy.dcm'] assert 0xC000 == item['Status'][1] ds = item['ds'] nr_frames = ds.get('NumberOfFrames', 1) frame = next(generate_pixel_data_frame(ds.PixelData, nr_frames)) msg = ( r"libjpeg error code '-1038' returned from GetJPEGParameters\(\): A " r"misplaced marker segment was found - scan start must be zero " r"and scan stop must be 63 for the sequential operating modes") with pytest.raises(RuntimeError, match=msg): get_parameters(frame)
def test_extended(self, fname, info): """Test get_parameters() for the LS lossy datasets.""" #info: (rows, columns, spp, bps) index = get_indexed_datasets('1.2.840.10008.1.2.4.81') ds = index[fname]['ds'] frame = next(self.generate_frames(ds)) arr = decode(np.frombuffer(frame, 'uint8'), reshape=True) if info[2] == 1: assert (info[0], info[1]) == arr.shape else: assert (info[0], info[1], info[2]) == arr.shape if 1 <= info[3] <= 8: assert arr.dtype == 'uint8' if 9 <= info[3] <= 16: assert arr.dtype == 'uint16'
def test_decode_bytes(): """Test decode using bytes.""" index = get_indexed_datasets('1.2.840.10008.1.2.4.50') ds = index['JPEGBaseline_1s_1f_u_08_08.dcm']['ds'] nr_frames = ds.get('NumberOfFrames', 1) frame = next(generate_pixel_data_frame(ds.PixelData, nr_frames)) arr = decode(frame) assert arr.flags.writeable assert 'uint8' == arr.dtype assert (ds.Rows, ds.Columns) == arr.shape # Reference values from GDCM handler assert 76 == arr[5, 50] assert 167 == arr[15, 50] assert 149 == arr[25, 50] assert 203 == arr[35, 50] assert 29 == arr[45, 50] assert 142 == arr[55, 50] assert 1 == arr[65, 50] assert 64 == arr[75, 50] assert 192 == arr[85, 50] assert 255 == arr[95, 50]
def setup(self): self.ds = get_indexed_datasets(self.uid)