def test_cascades(self): cascade0 = [ self.color_edges, lab.color_filter_from_greyscale_filter(lab.make_sharpen_filter(3)) ] cascade1 = [ lab.color_filter_from_greyscale_filter(lab.make_blur_filter(5)), self.color_edges, lab.color_filter_from_greyscale_filter(lab.make_sharpen_filter(3)) ] cascade3 = [self.color_edges] * 5 + [self.color_inverted] for fname in ('tree', ): for cix, cascade in enumerate([cascade0, cascade1]): inpfile = os.path.join(TEST_DIRECTORY, 'test_images', f'{fname}.png') expfile = os.path.join(TEST_DIRECTORY, 'test_results', f'{fname}_cascade{cix}.png') im = lab.load_color_image(inpfile) oim = object_hash(im) f_cascade = lab.filter_cascade(cascade) self.assertTrue(callable(f_cascade), 'filter_cascade should return a function.') result = f_cascade(im) expected = lab.load_color_image(expfile) self.assertEqual( object_hash(im), oim, 'Be careful not to modify the original image!') self.compare_color_images(result, expected)
def test_small_cascade(): color_edges = lab.color_filter_from_greyscale_filter(lab.edges) color_inverted = lab.color_filter_from_greyscale_filter(lab.inverted) color_blur_5 = lab.color_filter_from_greyscale_filter(lab.make_blur_filter(5)) im = lab.load_color_image('test_images/centered_pixel.png') expected = { 'height': 11, 'width': 11, 'pixels': [(255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (254, 250, 252), (254, 244, 248), (253, 240, 246), (253, 240, 246), (253, 240, 246), (254, 244, 248), (254, 250, 252), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (254, 244, 248), (253, 238, 244), (252, 227, 238), (252, 227, 238), (252, 227, 238), (253, 238, 244), (254, 244, 248), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (253, 240, 246), (252, 227, 238), (250, 211, 228), (250, 211, 228), (250, 211, 228), (252, 227, 238), (253, 240, 246), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (253, 240, 246), (252, 227, 238), (250, 211, 228), (250, 211, 228), (250, 211, 228), (252, 227, 238), (253, 240, 246), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (253, 240, 246), (252, 227, 238), (250, 211, 228), (250, 211, 228), (250, 211, 228), (252, 227, 238), (253, 240, 246), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (254, 244, 248), (253, 238, 244), (252, 227, 238), (252, 227, 238), (252, 227, 238), (253, 238, 244), (254, 244, 248), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (254, 250, 252), (254, 244, 248), (253, 240, 246), (253, 240, 246), (253, 240, 246), (254, 244, 248), (254, 250, 252), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255)] } f_cascade = lab.filter_cascade([color_edges, color_inverted, color_blur_5]) assert callable(f_cascade), 'filter_cascade should return a function.' result = f_cascade(im) compare_color_images(result, expected)
def test_cascade_2(self): im = lab.load_color_image('test_images/frog.png') filter1 = lab.color_filter_from_greyscale_filter(lab.edges) filter2 = lab.color_filter_from_greyscale_filter( lab.make_blur_filter(5)) filt = lab.filter_cascade([filter1, filter1, filter2, filter1]) result = filt(im) lab.save_color_image(result, '/Users/yaxinliu/Downloads/lab1/Cascade.png')
def test_blur_filter_2(self): blur_filter = lab.make_blur_filter(9) self.assertTrue(callable(blur_filter), 'make_blur_filter should return a function.') color_blur = lab.color_filter_from_greyscale_filter(blur_filter) im = lab.load_color_image('test_images/python.png') result = color_blur(im) lab.save_color_image( result, '/Users/yaxinliu/Downloads/lab1/Make_Blurred.png')
def test_blur_filter_1(self): blur_filter = lab.make_blur_filter(3) self.assertTrue(callable(blur_filter), 'make_blur_filter should return a function.') color_blur = lab.color_filter_from_greyscale_filter(blur_filter) im = lab.load_color_image('test_images/centered_pixel.png') result = color_blur(im) expected = { 'height': 11, 'width': 11, 'pixels': [(244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (245, 182, 193), (245, 182, 193), (245, 182, 193), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (245, 182, 193), (245, 182, 193), (245, 182, 193), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (245, 182, 193), (245, 182, 193), (245, 182, 193), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198)] } self.compare_color_images(result, expected)
def test_blur_filter_images(fname, ker_size): inpfile = os.path.join(TEST_DIRECTORY, 'test_images', f'{fname}.png') expfile = os.path.join(TEST_DIRECTORY, 'test_results', f'{fname}_blurred{ker_size}.png') im = lab.load_color_image(inpfile) oim = object_hash(im) blur_filter = lab.make_blur_filter(ker_size) assert callable(blur_filter), 'make_blur_filter should return a function.' color_blur = lab.color_filter_from_greyscale_filter(blur_filter) result = color_blur(im) expected = lab.load_color_image(expfile) assert object_hash(im) == oim, 'Be careful not to modify the original image!' compare_color_images(result, expected)
def test_blur_filters(self): for fname in ('cat', 'mushroom'): for ker_size in {3, 5}: with self.subTest(f=fname): inpfile = os.path.join(TEST_DIRECTORY, 'test_images', f'{fname}.png') expfile = os.path.join(TEST_DIRECTORY, 'test_results', f'{fname}_blurred{ker_size}.png') im = lab.load_color_image(inpfile) oim = object_hash(im) blur_filter = lab.make_blur_filter(ker_size) self.assertTrue( callable(blur_filter), 'make_blur_filter should return a function.') color_blur = lab.color_filter_from_greyscale_filter( blur_filter) result = color_blur(im) expected = lab.load_color_image(expfile) self.assertEqual( object_hash(im), oim, 'Be careful not to modify the original image!') self.compare_color_images(result, expected)
def test_blur_filter(): blur_filter = lab.make_blur_filter(3) assert callable(blur_filter), 'make_blur_filter should return a function.' color_blur = lab.color_filter_from_greyscale_filter(blur_filter) im = lab.load_color_image(os.path.join(TEST_DIRECTORY, 'test_images', 'centered_pixel.png')) result = color_blur(im) expected = { 'height': 11, 'width': 11, 'pixels': [(244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (245, 182, 193), (245, 182, 193), (245, 182, 193), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (245, 182, 193), (245, 182, 193), (245, 182, 193), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (245, 182, 193), (245, 182, 193), (245, 182, 193), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198), (244, 173, 198)] } compare_color_images(result, expected)
def test_cascades(cascade, image): color_edges = lab.color_filter_from_greyscale_filter(lab.edges) color_inverted = lab.color_filter_from_greyscale_filter(lab.inverted) cascade0 = [color_edges, lab.color_filter_from_greyscale_filter(lab.make_sharpen_filter(3))] cascade1 = [lab.color_filter_from_greyscale_filter(lab.make_blur_filter(5)), color_edges, lab.color_filter_from_greyscale_filter(lab.make_sharpen_filter(3)), lambda im: {k: ([(i[1], i[0], i[2]) for i in v] if isinstance(v, list) else v) for k, v in im.items()}] cascade2 = [color_edges]*5 + [color_inverted] cascades = [cascade0, cascade1, cascade2] inpfile = os.path.join(TEST_DIRECTORY, 'test_images', f'{image}.png') expfile = os.path.join(TEST_DIRECTORY, 'test_results', f'{image}_cascade{cascade}.png') im = lab.load_color_image(inpfile) oim = object_hash(im) f_cascade = lab.filter_cascade(cascades[cascade]) assert callable(f_cascade), 'filter_cascade should return a function.' result = f_cascade(im) expected = lab.load_color_image(expfile) assert object_hash(im) == oim, 'Be careful not to modify the original image!' compare_color_images(result, expected)
def setUp(self): self.color_edges = lab.color_filter_from_greyscale_filter(lab.edges) self.color_inverted = lab.color_filter_from_greyscale_filter( lab.inverted) self.color_blur_5 = lab.color_filter_from_greyscale_filter( lab.make_blur_filter(5))