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_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_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_cascade_1(self): im = lab.load_color_image('test_images/centered_pixel.png') f1 = self.color_edges f2 = self.color_inverted f3 = self.color_blur_5 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([f1, f2, f3]) self.assertTrue(callable(f_cascade), 'filter_cascade should return a function.') result = f_cascade(im) self.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)