Example #1
0
 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)
Example #2
0
 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)
Example #3
0
 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)
Example #4
0
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)
Example #5
0
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)
Example #6
0
 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))
Example #7
0
 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)
Example #8
0
 def test_edges_centered_pixel(self):
     im = lab.load_image('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
         ],
     }
     self.compare_images(result, expected)
Example #9
0
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)
Example #10
0
 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')