Exemplo n.º 1
0
    def test_detect_intersection_rect_T(self):
        image = np.array(
            [
                [False, False, False, False],
                [True, True, True, True],
                [True, True, True, True],
                [True, True, True, True],
                [False, True, True, False],
            ]
        )
        i_regions = [
            DirectedLine.btwn(*np.array([(3, 1), (1, 1)])),
            DirectedLine.btwn(*np.array([(3, 2), (1, 2)])),
            DirectedLine.btwn(*np.array([(3, 1), (3, 2)])),
            DirectedLine.btwn(*np.array([(2, 1), (2, 2)])),
            DirectedLine.btwn(*np.array([(1, 1), (1, 2)])),
        ]

        for line in i_regions:
            (top_left, bottom_right) = detect_intersection_rect(image, line)
            assert (
                top_left == 1
            ).all(), f"{line.direction}: Top left of junction should be [1 1] but was {top_left}"
            assert (
                bottom_right == np.array([3, 2])
            ).all(), f"{line.direction}: Intersection BR should be [3 2] but was {bottom_right}"

            line = line.reverse()
            (top_left, bottom_right) = detect_intersection_rect(image, line)
            assert (
                top_left == 1
            ).all(), f"{line.direction}: Top left of junction should be [1 1] but was {top_left}"
            assert (
                bottom_right == np.array([3, 2])
            ).all(), f"{line.direction}: Intersection BR should be [3 2] but was {bottom_right}"
Exemplo n.º 2
0
    def test_detect_intersection_rect_L_270(self):
        image = np.array(
            [
                [False, True, True, False],
                [True, True, True, False],
                [True, True, True, False],
                [False, False, False, False],
            ]
        )

        i_regions = [
            DirectedLine.btwn(*np.array([(1, 1), (1, 2)])),
            DirectedLine.btwn(*np.array([(1, 2), (1, 1)])),
            DirectedLine.btwn(*np.array([(1, 1), (2, 1)])),
            DirectedLine.btwn(*np.array([(2, 1), (1, 1)])),
        ]

        for line in i_regions:
            (top_left, bottom_right) = detect_intersection_rect(image, line)
            assert (top_left == 1).all()
            assert (bottom_right == 2).all()
Exemplo n.º 3
0
 def test_detect_intersection_big(self):
     image = np.zeros((20, 20), dtype=bool)
     image[:, 12] = True
     image[5, :] = True
     line = DirectedLine.btwn(np.array([10, 12]), np.array([0, 12]))
     intersection = line.detect_intersection(image)
     assert intersection
     (x, y, width, height) = intersection.bounding_box()
     assert x == 12
     assert y == 5
     assert width == 1
     assert height == 1
     assert line.remove_overlap_into(intersection.bounding_box())
Exemplo n.º 4
0
    def test_detect_intersection_rect_L(self):
        image = np.array(
            [
                [False, True, True, False],
                [False, True, True, True],
                [False, True, True, True],
                [False, False, False, False],
            ]
        )
        i_regions = [
            DirectedLine.btwn(*np.array([(1, 1), (1, 2)])),
            DirectedLine.btwn(*np.array([(1, 2), (1, 1)])),
            DirectedLine.btwn(*np.array([(1, 2), (2, 2)])),
            DirectedLine.btwn(*np.array([(2, 2), (1, 2)])),
        ]

        for line in i_regions:
            (top_left, bottom_right) = detect_intersection_rect(image, line)
            assert (
                top_left == 1
            ).all(), f"Expected top left to be [1 1]. Found {top_left}"
            assert (
                bottom_right == 2
            ).all(), f"Expected bottom right to be [2 2]. Found {bottom_right}"
Exemplo n.º 5
0
 def test_detect_intersection(self):
     image = np.array(
         [
             [False, False, True, False, False, False, False],
             [False, False, True, True, True, True, True],
             [False, False, True, False, False, False, False],
             [False, False, True, False, True, False, False],
             [False, False, True, False, False, False, False],
             [False, False, True, False, False, False, False],
             [False, False, True, False, False, False, False],
         ]
     )
     line = DirectedLine.btwn(np.array([6, 2]), np.array([0, 2]))
     intersection = line.detect_intersection(image)
     assert intersection
     (x, y, width, height) = intersection.bounding_box()
     assert width == 1
     assert height == 1
     assert line.remove_overlap_into(intersection.bounding_box())