Exemplo n.º 1
0
    def test_edge_overlap(self):
        """
        When an image is split and reconstructed such that image parts combine
        to appear like the template, we can get false positives in strange
        places.
        """
        image = np.array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                          [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                          [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                          [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                          [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                          [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                          [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                          [1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0],
                          [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                          [1, 1, 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]])
        template = np.array([[1, 1, 1],
                             [0, 1, 0],
                             [1, 1, 1]])

        expected = []
        actual = overlapped_convolution(template, image)
        self.assertEquals(sorted(expected), sorted(actual))
Exemplo n.º 2
0
    def test_no_match(self):
        blank = np.zeros((100, 100))
        template = np.array([[0, 1], [1, 0]])

        expected = []
        actual = overlapped_convolution(template, blank)
        self.assertEquals(expected, actual)
Exemplo n.º 3
0
    def test_match(self):
        image = np.array([[0, 0, 0, 0, 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, 1, 0, 0],
                          [0, 0, 0, 0, 0, 0, 0, 0],
                          [0, 0, 1, 0, 0, 0, 0, 0],
                          [0, 1, 0, 0, 0, 0, 0, 0],
                          [0, 0, 0, 0, 0, 0, 0, 0]])
        template = np.array([[0, 1], [1, 0]])

        expected = [(1, 5), (5, 2)]
        actual = overlapped_convolution(template, image)
        self.assertEquals(sorted(expected), sorted(actual))