def test_edges(self): for fname in ('mushroom', 'twocats', 'chess'): with self.subTest(f=fname): inpfile = os.path.join(TEST_DIRECTORY, 'test_images', '%s.png' % fname) expfile = os.path.join(TEST_DIRECTORY, 'test_results', '%s_edges.png' % fname) input_img = lab.load_image(inpfile) input_hash = object_hash(input_img) result = lab.edges(input_img) expected = lab.load_image(expfile) self.assertEqual(object_hash(input_img), input_hash, "Be careful not to modify the original image!") self.compare_images(result, expected)
def test_inverted_images(self): for fname in ('mushroom', 'twocats', 'chess'): with self.subTest(f=fname): inpfile = os.path.join(TEST_DIRECTORY, 'test_images', '%s.png' % fname) expfile = os.path.join(TEST_DIRECTORY, 'test_results', '%s_invert.png' % fname) im = lab.load_image(inpfile) oim = object_hash(im) result = lab.inverted(im) expected = lab.load_image(expfile) self.assertEqual(object_hash(im), oim, 'Be careful not to modify the original image!') self.compare_images(result, expected)
def test_inverted_images(fname): inpfile = os.path.join(TEST_DIRECTORY, 'test_images', '%s.png' % fname) expfile = os.path.join(TEST_DIRECTORY, 'test_results', '%s_invert.png' % fname) im = lab.load_image(inpfile) oim = object_hash(im) result = lab.inverted(im) expected = lab.load_image(expfile) assert object_hash( im) == oim, 'Be careful not to modify the original image!' compare_images(result, expected)
def test_sharpened_images(kernsize, fname): inpfile = os.path.join(TEST_DIRECTORY, 'test_images', '%s.png' % fname) expfile = os.path.join(TEST_DIRECTORY, 'test_results', '%s_sharp_%02d.png' % (fname, kernsize)) input_img = lab.load_image(inpfile) input_hash = object_hash(input_img) result = lab.sharpened(input_img, kernsize) expected = lab.load_image(expfile) assert object_hash( input_img ) == input_hash, "Be careful not to modify the original image!" compare_images(result, expected)
def test_edges_images(fname): inpfile = os.path.join(TEST_DIRECTORY, 'test_images', '%s.png' % fname) expfile = os.path.join(TEST_DIRECTORY, 'test_results', '%s_edges.png' % fname) input_img = lab.load_image(inpfile) input_hash = object_hash(input_img) result = lab.edges(input_img) expected = lab.load_image(expfile) assert object_hash( input_img ) == input_hash, "Be careful not to modify the original image!" compare_images(result, expected)
def test_sharpened(self): for kernsize in (1, 3, 9): for fname in ('mushroom', 'twocats', 'chess'): with self.subTest(k=kernsize, f=fname): inpfile = os.path.join(TEST_DIRECTORY, 'test_images', '%s.png' % fname) expfile = os.path.join(TEST_DIRECTORY, 'test_results', '%s_sharp_%02d.png' % (fname, kernsize)) input_img = lab.load_image(inpfile) input_hash = object_hash(input_img) result = lab.sharpened(input_img, kernsize) expected = lab.load_image(expfile) self.assertEqual(object_hash(input_img), input_hash, "Be careful not to modify the original image!") self.compare_images(result, expected)
def test_blurred_centered_pixel(kernsize, fname): # REPLACE THIS with your 2nd test case from section 5.1 inpfile = os.path.join(TEST_DIRECTORY, 'test_images', '%s.png' % fname) expfile = os.path.join(TEST_DIRECTORY, 'test_results', '%s_blur_%02d.png' % (fname, kernsize)) input_img = lab.load_image(inpfile) input_hash = object_hash(input_img) result = lab.blurred(input_img, kernsize) expected = lab.load_image(expfile) assert object_hash( input_img ) == input_hash, "Be careful not to modify the original image!" compare_images(result, expected)
def test_blurred_centered_pixel(): im = lab.load_image( os.path.join(TEST_DIRECTORY, 'test_images', 'centered_pixel.png')) result3 = lab.blurred(im, 3) result5 = lab.blurred(im, 5) expected3 = { '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, 28, 28, 28, 0, 0, 0, 0, 0, 0, 0, 0, 28, 28, 28, 0, 0, 0, 0, 0, 0, 0, 0, 28, 28, 28, 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 ] } expected5 = { '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, 10, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 10, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 10, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 10, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 10, 10, 10, 10, 10, 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_images(result3, expected3) compare_images(result5, expected5)
def test_blurred_centered_pixel(self): im = lab.load_image('test_images/centered_pixel.png') result1 = lab.blurred(im, 3) result2 = lab.blurred(im, 5) expected1 = { '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, 28, 28, 28, 0, 0, 0, 0, 0, 0, 0, 0, 28, 28, 28, 0, 0, 0, 0, 0, 0, 0, 0, 28, 28, 28, 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 ], } expected2 = { '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, 10, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 10, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 10, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 10, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 10, 10, 10, 10, 10, 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 ], } self.compare_images(result1, expected1) self.compare_images(result2, expected2)
def test_blurred_centered_pixel(self): # REPLACE THIS with your 2nd test case from section 5.1 cent_pixel = lab.load_image('test_images/centered_pixel.png') exp_3 = { '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, 28, 28, 28, 0, 0, 0, 0, 0, 0, 0, 0, 28, 28, 28, 0, 0, 0, 0, 0, 0, 0, 0, 28, 28, 28, 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 ] } exp_5 = { '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, 10, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 10, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 10, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 10, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 10, 10, 10, 10, 10, 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 ] } self.compare_images(exp_3, lab.blurred(cent_pixel, 3)) self.compare_images(exp_5, lab.blurred(cent_pixel, 5))
def test_edges_centered_pixel(self): # 6: Edge detection on the centered_pixel.png image fname = 'centered_pixel' with self.subTest(f=fname): inpfile = os.path.join(TEST_DIRECTORY, 'test_images', '%s.png' % fname) input_img = lab.load_image(inpfile) input_hash = object_hash(input_img) result = lab.edges(input_img) 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, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 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 ] } self.assertEqual(object_hash(input_img), input_hash, "Be careful not to modify the original image!") self.compare_images(result, expected)
def test_blurred_black_image(kernsize, fname): # REPLACE THIS with your 1st test case from section 5.1 inpfile = os.path.join(TEST_DIRECTORY, 'test_images', '%s.png' % fname) #im = lab.load_image(os.path.join(TEST_DIRECTORY, 'test_images', 'all_black.png')) expected = {'height': 6, 'width': 5, 'pixels': [0] * 6 * 5} input_img = lab.load_image(inpfile) result = lab.blurred(input_img, kernsize) compare_images(result, expected)
def test_edges_centered_pixel(self): im = lab.load_image("test_images/centered_pixel.png") result = lab.edges(im) expected = im.copy() for i in [60, 60 - 11, 60 + 11]: expected["pixels"][i - 1] = 255 expected["pixels"][i] = 255 expected["pixels"][i + 1] = 255 expected["pixels"][60] = 0 self.compare_images(result, expected)
def test_correlate_3(self): kernel = [[0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 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]] im = lab.load_image('test_images/pigbird.png') result = lab.correlate(im, kernel) lab.save_image(result, '/Users/yaxinliu/Downloads/lab0/CorrelatedImage.png')
def test_blurred_centered_pixel(self): # 5.1: Box blurs for the centered_pixel.png image (2 different kernel sizes) for kernsize in (1, 3): fname = 'centered_pixel' with self.subTest(k=kernsize, f=fname): inpfile = os.path.join(TEST_DIRECTORY, 'test_images', '%s.png' % fname) input_img = lab.load_image(inpfile) input_hash = object_hash(input_img) result = lab.blurred(input_img, kernsize) if kernsize == 1: 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, 255, 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 ] } else: 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, 28, 28, 28, 0, 0, 0, 0, 0, 0, 0, 0, 28, 28, 28, 0, 0, 0, 0, 0, 0, 0, 0, 28, 28, 28, 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 ] } self.assertEqual( object_hash(input_img), input_hash, "Be careful not to modify the original image!") self.compare_images(result, expected)
def test_load(self): result = lab.load_image('test_images/centered_pixel.png') 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, 255, 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 ], } self.compare_images(result, expected)
def test_load(): result = lab.load_image( os.path.join(TEST_DIRECTORY, 'test_images', 'centered_pixel.png')) 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, 255, 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_images(result, expected)
def test_edges_centered_pixel(self): # REPLACE THIS with your test case from section 6 im = lab.load_image('test_images/centered_pixel.png') 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, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 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 ] } return self.compare_images(lab.edges(im), expected)
def test_correlate_1(self): kernel = [[0, 0, 0], [0, 1, 0], [0, 0, 0]] im = lab.load_image('test_images/centered_pixel.png') result = lab.correlate(im, kernel) 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, 255, 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 ], } self.compare_images(result, expected)
def test_edges_centered_pixel(self): # REPLACE THIS with your test case from section 6 exp = { '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, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 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 ] } image = lab.load_image('test_images/centered_pixel.png') self.compare_images(exp, lab.edges(image))
def test_edges_centered_pixel(): inpfile = os.path.join(TEST_DIRECTORY, 'test_images', 'centered_pixel.png') image = lab.load_image(inpfile) 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, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 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 ], } result = lab.edges(image) compare_images(result, expected)
def test_edges_centered_pixel(): # REPLACE THIS with your test case from section 6 im = lab.load_image( os.path.join(TEST_DIRECTORY, 'test_images', 'centered_pixel.png')) result = lab.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, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 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_images(result, expected)
def test_inverted_1(self): im = lab.load_image('test_images/centered_pixel.png') print('im:', im) result = lab.inverted(im) print('result:', result) 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, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255], } self.compare_images(result, expected)
def test_blurred_centered_pixel(self): im = lab.load_image("test_images/centered_pixel.png") result1 = lab.blurred(im, 3) elem1 = round(255 / 9) expected1 = { "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, elem1, elem1, elem1, 0, 0, 0, 0, 0, 0, 0, 0, elem1, elem1, elem1, 0, 0, 0, 0, 0, 0, 0, 0, elem1, elem1, elem1, 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 ] } self.compare_images(result1, expected1) result2 = lab.blurred(im, 5) elem2 = round(255 / 25) expected2 = { '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, elem2, elem2, elem2, elem2, elem2, 0, 0, 0, 0, 0, 0, elem2, elem2, elem2, elem2, elem2, 0, 0, 0, 0, 0, 0, elem2, elem2, elem2, elem2, elem2, 0, 0, 0, 0, 0, 0, elem2, elem2, elem2, elem2, elem2, 0, 0, 0, 0, 0, 0, elem2, elem2, elem2, elem2, elem2, 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 ], } self.compare_images(result2, expected2)
def test_blurred_centered_pixel(self): # REPLACE THIS with your 2nd test case from section 5.1 im = lab.load_image('test_images/centered_pixel.png') blurred1 = lab.blurred(im, 3) correct1 = { 'height': im['height'], 'width': im['width'], '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, 28, 28, 28, 0, 0, 0, 0, 0, 0, 0, 0, 28, 28, 28, 0, 0, 0, 0, 0, 0, 0, 0, 28, 28, 28, 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 ] } blurred2 = lab.blurred(im, 5) correct2 = { 'height': im['height'], 'width': im['width'], '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, 10, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 10, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 10, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 10, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 10, 10, 10, 10, 10, 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 ] } return self.compare_images(blurred1, correct1) and self.compare_images( blurred2, correct2)
def test_inverted_1(): im = lab.load_image( os.path.join(TEST_DIRECTORY, 'test_images', 'centered_pixel.png')) result = lab.inverted(im) 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, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 ], } compare_images(result, expected)
def test_blurred_centered_pixel(): inpfile = os.path.join(TEST_DIRECTORY, 'test_images', 'centered_pixel.png') image = lab.load_image(inpfile) 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, 28, 28, 28, 0, 0, 0, 0, 0, 0, 0, 0, 28, 28, 28, 0, 0, 0, 0, 0, 0, 0, 0, 28, 28, 28, 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 ], } result = lab.blurred(image, 3) compare_images(result, expected) 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, 10, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 10, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 10, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 10, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 10, 10, 10, 10, 10, 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 ], } result = lab.blurred(image, 5) compare_images(result, expected)
def test_edges_construct(self): im = lab.load_image('test_images/construct.png') result = lab.edges(im) lab.save_image(result, '/Users/yaxinliu/Downloads/lab0/edgesImage.png')
def test_blurred_cat(self): im = lab.load_image('test_images/cat.png') result = lab.blurred(im, 5) lab.save_image(result, '/Users/yaxinliu/Downloads/lab0/BlurredCat.png')
def test_sharpened_1(self): im = lab.load_image('test_images/python.png') result = lab.sharpened(im, 11) lab.save_image(result, '/Users/yaxinliu/Downloads/lab0/sharpenedImage.png')