def test_q3a_convert_rgb_to_greyscale(): colour_file = pathlib.Path() / 'samples' / 'rocket.ppm' grey_file = pathlib.Path() / 'samples' / 'rocket-greyscale.pgm' image = imread(str(colour_file)) greyscale = rgb2grey(image) expected = imread(str(grey_file)) assert greyscale.dtype == np.uint8 imwrite(pathlib.Path() / 'test.pgm', greyscale) assert_array_equal(greyscale, expected)
def test_q1b_read_colour_image(): expected = np.array([ [[255, 0, 0], [0, 0, 0], [255, 255, 255], [255, 255, 255]], [[0, 0, 0], [0, 255, 0], [0, 0, 255], [255, 255, 255]], [[0, 0, 0], [255, 0, 0], [0, 255, 255], [0, 0, 0]], [[255, 255, 0], [0, 0, 0], [0, 0, 0], [255, 0, 255]] ], dtype=np.uint8) filename = pathlib.Path() / 'samples' / 'colour.ppm' image = imread(filename.absolute()) assert_array_equal(expected, image)
def test_q4a_convert_grey_to_pseudo_colour(): grey_file = pathlib.Path() / 'samples' / 'rocket-greyscale.pgm' image = imread(str(grey_file)) rgb = grey2rgb(image) assert rgb.dtype == np.uint8 assert rgb.ndim == 3 assert rgb.shape[2] == 3 for i in range(3): assert_array_equal(rgb[:, :, i], image)
def test_q1a_read_greyscale_image(): expected = np.array([ [255, 0, 255, 255], [0, 255, 255, 255], [0, 255, 255, 0], [255, 0, 0, 255] ], dtype=np.uint8) filename = pathlib.Path() / 'samples' / 'greyscale.pgm' image = imread(filename.absolute()) assert_array_equal(expected, image)
def convert_image(rgb_image, grey_image): image = imread(rgb_image) greyscale = rgb2grey(image) imwrite(grey_image, greyscale)
def test_q1c_unsupported_type_raises_exception(): filename = pathlib.Path() / 'samples' / 'colour-binary.pbm' with pytest.raises(ValueError): imread(filename.absolute())