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 seams_endtoend(inp_name, out_name, number): inpfile = os.path.join(TEST_DIRECTORY, 'test_images', inp_name) im = lab.load_color_image(inpfile) oim = object_hash(im) for i in range(1, number): result = lab.seam_carving(im, i) assert object_hash(im) == oim, 'Be careful not to modify the original image!' expfile = os.path.join(TEST_DIRECTORY, 'test_results', out_name, f'{i:02d}.png') compare_color_images(result, lab.load_color_image(expfile))
def seams_one(images): for i in images: inpfile = os.path.join(TEST_DIRECTORY, 'test_images', f'{i}.png') im = lab.load_color_image(inpfile) oim = object_hash(im) result = lab.seam_carving(im, 1) assert object_hash(im) == oim, 'Be careful not to modify the original image!' expfile = os.path.join(TEST_DIRECTORY, 'test_results', f'{i}_1seam.png') compare_color_images(result, lab.load_color_image(expfile))
def test_seam_removal(): for fname in ('pattern', 'bluegill', 'twocats', 'tree'): infile = os.path.join(TEST_DIRECTORY, 'test_results', f'{fname}_minimum_energy_seam.pickle') with open(infile, 'rb') as f: seam = pickle.load(f) imfile = os.path.join(TEST_DIRECTORY, 'test_images', f'{fname}.png') result = lab.image_without_seam(lab.load_color_image(imfile), seam) expfile = os.path.join(TEST_DIRECTORY, 'test_results', f'{fname}_1seam.png') compare_color_images(result, lab.load_color_image(expfile))
def test_color_filter_images(fname, filter_info): filt, filt_name = filter_info inpfile = os.path.join(TEST_DIRECTORY, 'test_images', f'{fname}.png') expfile = os.path.join(TEST_DIRECTORY, 'test_results', f'{fname}_{filt_name}.png') im = lab.load_color_image(inpfile) oim = object_hash(im) color_filter = lab.color_filter_from_greyscale_filter(filt) assert callable(color_filter), 'color_filter_from_greyscale_filter should return a function.' result = color_filter(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_sharpen_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}_sharpened{ker_size}.png') im = lab.load_color_image(inpfile) oim = object_hash(im) sharpen_filter = lab.make_sharpen_filter(ker_size) assert callable(sharpen_filter), 'make_sharpen_filter should return a function.' color_sharpen = lab.color_filter_from_greyscale_filter(sharpen_filter) result = color_sharpen(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_endtoend_smallfrog(self): inpfile = os.path.join(TEST_DIRECTORY, 'test_images', 'smallfrog.png') im = lab.load_color_image(inpfile) oim = object_hash(im) for i in range(1, 31): result = lab.seam_carving(im, i) self.assertEqual(object_hash(im), oim, 'Be careful not to modify the original image!') expfile = os.path.join(TEST_DIRECTORY, 'test_results', 'seams_smallfrog', f'{i:02d}.png') self.compare_color_images(result, lab.load_color_image(expfile))
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_endtoend_twocats(self): inpfile = os.path.join(TEST_DIRECTORY, 'test_images', 'twocats.png') im = lab.load_color_image(inpfile) oim = object_hash(im) result = lab.seam_carving(im, 100) lab.save_color_image(result, '/Users/yaxinliu/Downloads/lab1/Seam.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_sharpen_filters_1(self): sharpen_filter = lab.make_sharpen_filter(7) self.assertTrue(callable(sharpen_filter), 'make_sharpen_filter should return a function.') color_sharpen = lab.color_filter_from_greyscale_filter(sharpen_filter) im = lab.load_color_image('test_images/sparrowchick.png') result = color_sharpen(im) lab.save_color_image( result, '/Users/yaxinliu/Downloads/lab1/Make_Sharpen.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_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_greyscale(): for fname in ('centered_pixel', 'pattern', 'smallfrog', 'bluegill', 'twocats', 'tree'): inpfile = os.path.join(TEST_DIRECTORY, 'test_images', f'{fname}.png') im = lab.load_color_image(inpfile) oim = object_hash(im) grey = lab.greyscale_image_from_color_image(im) expfile = os.path.join(TEST_DIRECTORY, 'test_results', f'{fname}_grey.png') assert object_hash(im) == oim, 'Be careful not to modify the original image!' compare_greyscale_images(grey, load_greyscale_image(expfile))
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_color_filters(self): for fname in ('frog', 'tree'): for filt, filt_name in {(lab.edges, 'edges'), (lab.inverted, 'inverted')}: 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}_{filt_name}.png') im = lab.load_color_image(inpfile) oim = object_hash(im) color_filter = lab.color_filter_from_greyscale_filter(filt) self.assertTrue( callable(color_filter), 'color_filter_from_greyscale_filter should return a function.' ) result = color_filter(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_sharpen_filters(self): for fname in ('construct', 'bluegill'): 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}_sharpened{ker_size}.png') im = lab.load_color_image(inpfile) oim = object_hash(im) sharpened_filter = lab.make_sharpen_filter(ker_size) self.assertTrue( callable(sharpened_filter), 'make_sharpen_filter should return a function.') color_sharpen = lab.color_filter_from_greyscale_filter( sharpened_filter) result = color_sharpen(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_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 test_load_color(self): im = lab.load_color_image('test_images/centered_pixel.png') 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), (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), (253, 253, 149), (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), (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_color_filter_inverted(self): im = lab.load_color_image('test_images/centered_pixel.png') color_inverted = lab.color_filter_from_greyscale_filter(lab.inverted) self.assertTrue( callable(color_inverted), 'color_filter_from_greyscale_filter should return a function.') result = color_inverted(im) expected = { 'height': 11, 'width': 11, 'pixels': [(11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (2, 2, 106), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57)] } self.compare_color_images(result, expected)
def test_load_color(): result = lab.load_color_image(os.path.join(TEST_DIRECTORY, 'test_images', 'centered_pixel.png')) 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), (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), (253, 253, 149), (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), (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_color_filter_edges(): im = lab.load_color_image('test_images/centered_pixel.png') color_edges = lab.color_filter_from_greyscale_filter(lab.edges) assert callable(color_edges), 'color_filter_from_greyscale_filter should return a function.' result = color_edges(im) expected = { 'height': 11, 'width': 11, 'pixels': [(0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (13, 113, 69), (18, 160, 98), (13, 113, 69), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (18, 160, 98), (0, 0, 0), (18, 160, 98), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (13, 113, 69), (18, 160, 98), (13, 113, 69), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0)], } compare_color_images(result, expected)
def test_color_filter_inverted(): im = lab.load_color_image(os.path.join(TEST_DIRECTORY, 'test_images', 'centered_pixel.png')) color_inverted = lab.color_filter_from_greyscale_filter(lab.inverted) assert callable(color_inverted), 'color_filter_from_greyscale_filter should return a function.' result = color_inverted(im) expected = { 'height': 11, 'width': 11, 'pixels': [(11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (2, 2, 106), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57), (11, 82, 57)] } 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_color_filter_inverted_2(self): im = lab.load_color_image('test_images/cat.png') color_inverted = lab.color_filter_from_greyscale_filter(lab.inverted) result = color_inverted(im) lab.save_color_image( result, '/Users/yaxinliu/Downloads/lab1/ColorFilterInverted.png')
def test_endtoend_centeredpixel_2(self): im = lab.load_color_image('test_images/chess.png') result = lab.threshold(im, 150, 170) lab.save_color_image( result, '/Users/yaxinliu/Downloads/lab1/CreativeFilte_2.png')
def test_endtoend_centeredpixel_1(self): im = lab.load_color_image('test_images/centered_pixel.png') result = lab.threshold(im, 0, 255) lab.save_color_image( result, '/Users/yaxinliu/Downloads/lab1/CreativeFilter_1.png')