示例#1
0
 def test_blurred_black_image(self):
     im = {
         'height':
         6,
         'width':
         5,
         '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
         ],
     }
     result1 = lab.blurred(im, 3)
     result2 = lab.blurred(im, 7)
     expected = {
         'height':
         6,
         'width':
         5,
         '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
         ],
     }
     self.compare_images(result1, expected)
     self.compare_images(result2, expected)
示例#2
0
 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))
示例#3
0
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)
示例#4
0
 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)
示例#5
0
    def test_blurred_black_image(self):
        # REPLACE THIS with your 1st test case from section 5.1
        pixels = []
        for i in range(30):
            pixels.append(255)

        im = {'height': 6, 'width': 5, 'pixels': pixels}
        im_blurred1 = lab.blurred(im, 9)
        im_blurred2 = lab.blurred(im, 11)

        return self.compare_images(im_blurred1, im) and self.compare_images(
            im_blurred2, im)
示例#6
0
 def test_blurred_black_image(self):
     # REPLACE THIS with your 1st test case from section 5.1
     black_image = {
         'height':
         6,
         'width':
         5,
         '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
         ]
     }
     self.compare_images(black_image, lab.blurred(black_image, 3))
     self.compare_images(black_image, lab.blurred(black_image, 5))
示例#7
0
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)
示例#8
0
    def test_blurred_black_image(self):
        # 5.1: Box blurs of a 6x5 image with black pixels (2 different kernel sizes)
        w = 6
        h = 5
        input_img = {'height': h, 'width': w, 'pixels': [0] * w * h}

        for kernsize in (1, 3):
            result = lab.blurred(input_img, kernsize)
            expected = {'height': h, 'width': w, 'pixels': [0] * w * h}
            self.compare_images(result, expected)
示例#9
0
 def test_blurred(self):
     for kernsize in (1, 3, 7):
         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_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)
                 self.assertEqual(object_hash(input_img), input_hash, "Be careful not to modify the original image!")
                 self.compare_images(result, expected)
示例#10
0
def test_blurred_images(kernsize, fname):
    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)
示例#11
0
    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)
示例#12
0
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)
示例#13
0
    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)
示例#14
0
    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)
示例#15
0
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)
示例#16
0
 def test_blurred_black_image(self):
     for kernel_size in [3, 5]:
         im = {"width": 6, "height": 5, "pixels": [0] * (6 * 5)}
         expected = im.copy()
         result = lab.blurred(im, kernel_size)
         self.compare_images(result, expected)
示例#17
0
def test_blurred_black_image():
    image = {'height': 5, 'width': 6, 'pixels': [0] * 6 * 5}
    result = lab.blurred(image, 3)
    compare_images(result, image)
    result = lab.blurred(image, 5)
    compare_images(result, image)
示例#18
0
 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')
示例#19
0
def test_blurred_black_image():
    expected = {'height': 5, 'width': 6, 'pixels': [255] * 30}
    result1 = lab.blurred(expected, 3)
    result2 = lab.blurred(expected, 5)
    compare_images(result1, expected)
    compare_images(result2, expected)