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_str(self): """Test decoding using a str path.""" p = DIR_10918 / 'p1' / 'A1.JPG' p = os.fspath(p) assert isinstance(p, str) arr = decode(p) assert arr.shape == (257, 255, 4)
def test_jnl(self, fname, info, ref): """Test decoding the JPEG-LS near lossless compliance images.""" #info: (rows, columns, spp, bps) with open(os.path.join(DIR_14495, 'JNL', fname), 'rb') as fp: data = fp.read() arr = decode(np.frombuffer(data, 'uint8'), reshape=True) assert arr.flags.writeable 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' if info[2] == 1: assert ref[0] == arr[0, 0].tolist() assert ref[1] == arr[-1, -1].tolist() else: assert ref[0] == arr[0, 0, :].tolist() assert ref[1] == arr[-1, -1, :].tolist()
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_extended_p2(self, fname, info, ref): """Test decoding the extended p2 compliance images.""" #info: (rows, columns, spp, bps) with open(os.path.join(DIR_10918, 'p2', fname), 'rb') as fp: data = fp.read() arr = decode(np.frombuffer(data, 'uint8'), reshape=True) assert arr.flags.writeable if info[2] == 1: assert (info[0], info[1]) == arr.shape else: assert (info[0], info[1], info[2]) == arr.shape # Process 2 is always 8-bit assert arr.dtype == 'uint8' assert ref[0] == arr[0, 0, :].tolist() assert ref[1] == arr[-1, -1, :].tolist()
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 test_invalid_buffer(self): """Test that an invalid colour transform raises an exception.""" msg = (r"Buffer dtype mismatch, expected 'uint8_t' but got 'double'") with pytest.raises(ValueError, match=msg): decode(np.zeros(1), 'YBR_FULL')
def test_path(self): """Test decoding using a Path path.""" p = DIR_10918 / 'p1' / 'A1.JPG' assert isinstance(p, Path) arr = decode(p) assert arr.shape == (257, 255, 4)