Exemple #1
0
    def _test_cbaoi_p_is_0(self, augf_name, cbaoi, deterministic):
        aug = self.create_aug(0)
        if deterministic:
            aug = aug.to_deterministic()

        for _ in sm.xrange(3):
            observed = getattr(aug, augf_name)(cbaoi)
            assert_cbaois_equal(observed, cbaoi)
    def test_augment_polygons__kernel_size_is_two__keep_size(self):
        from imgaug.augmentables.polys import Polygon, PolygonsOnImage
        polys = [Polygon([(0, 0), (2, 0), (2, 2)])]
        psoi = PolygonsOnImage(polys, shape=(6, 6, 3))
        aug = self.augmenter(2, keep_size=True)

        psoi_aug = aug.augment_polygons(psoi)

        assert_cbaois_equal(psoi_aug, psoi)
    def _test_augment_keypoints__kernel_size_is_noop(self, kernel_size):
        from imgaug.augmentables.kps import Keypoint, KeypointsOnImage
        kps = [Keypoint(x=1.5, y=5.5), Keypoint(x=5.5, y=1.5)]
        kpsoi = KeypointsOnImage(kps, shape=(6, 6, 3))
        aug = self.augmenter(kernel_size)

        kpsoi_aug = aug.augment_keypoints(kpsoi)

        assert_cbaois_equal(kpsoi_aug, kpsoi)
    def test_augment_bounding_boxes__kernel_size_is_two__keep_size(self):
        from imgaug.augmentables.bbs import BoundingBox, BoundingBoxesOnImage
        bbs = [BoundingBox(x1=0, y1=0, x2=2, y2=2)]
        bbsoi = BoundingBoxesOnImage(bbs, shape=(6, 6, 3))
        aug = self.augmenter(2, keep_size=True)

        bbsoi_aug = aug.augment_bounding_boxes(bbsoi)

        assert_cbaois_equal(bbsoi_aug, bbsoi)
    def test_empty_keypoints(self):
        from imgaug.augmentables.kps import KeypointsOnImage
        kpsoi = KeypointsOnImage([], shape=(5, 6, 3))
        aug = self.augmenter(3, keep_size=False)

        kpsoi_aug = aug.augment_keypoints(kpsoi)

        expected = kpsoi.deepcopy(shape=(2, 2, 3))
        assert_cbaois_equal(kpsoi_aug, expected)
    def test_empty_bounding_boxes(self):
        from imgaug.augmentables.bbs import BoundingBoxesOnImage
        bbsoi = BoundingBoxesOnImage([], shape=(5, 6, 3))
        aug = self.augmenter(3, keep_size=False)

        bbsoi_aug = aug.augment_bounding_boxes(bbsoi)

        expected = bbsoi.deepcopy()
        expected.shape = (2, 2, 3)
        assert_cbaois_equal(bbsoi_aug, expected)
    def test_empty_polygons(self):
        from imgaug.augmentables.polys import PolygonsOnImage
        psoi = PolygonsOnImage([], shape=(5, 6, 3))
        aug = self.augmenter(3, keep_size=False)

        psoi_aug = aug.augment_polygons(psoi)

        expected = psoi.deepcopy()
        expected.shape = (2, 2, 3)
        assert_cbaois_equal(psoi_aug, expected)
    def test_augment_keypoints__kernel_size_is_two__no_keep_size(self):
        from imgaug.augmentables.kps import Keypoint, KeypointsOnImage
        kps = [Keypoint(x=1.5, y=5.5), Keypoint(x=5.5, y=1.5)]
        kpsoi = KeypointsOnImage(kps, shape=(6, 6, 3))
        aug = self.augmenter(2, keep_size=False)

        kpsoi_aug = aug.augment_keypoints(kpsoi)

        expected = KeypointsOnImage.from_xy_array(np.float32(
            [[1.5 / 2, 5.5 / 2], [5.5 / 2, 1.5 / 2]]),
                                                  shape=(3, 3, 3))
        assert_cbaois_equal(kpsoi_aug, expected)
    def test_augment_bounding_boxes__kernel_size_is_two__no_keep_size(self):
        from imgaug.augmentables.bbs import BoundingBox, BoundingBoxesOnImage
        bbs = [BoundingBox(x1=1.5, y1=2.5, x2=3.5, y2=4.5)]
        bbsoi = BoundingBoxesOnImage(bbs, shape=(6, 6, 3))
        aug = self.augmenter(2, keep_size=False)

        bbsoi_aug = aug.augment_bounding_boxes(bbsoi)

        expected = BoundingBoxesOnImage(
            [BoundingBox(x1=1.5 / 2, y1=2.5 / 2, x2=3.5 / 2, y2=4.5 / 2)],
            shape=(3, 3, 3))
        assert_cbaois_equal(bbsoi_aug, expected)
Exemple #10
0
    def test_augment_polygons__kernel_size_is_two__no_keep_size(self):
        from imgaug.augmentables.polys import Polygon, PolygonsOnImage
        ps = [Polygon([(1.5, 1.5), (5.5, 1.5), (5.5, 5.5)])]
        psoi = PolygonsOnImage(ps, shape=(6, 6, 3))
        aug = self.augmenter(2, keep_size=False)

        psoi_aug = aug.augment_polygons(psoi)

        expected = PolygonsOnImage([
            Polygon([(1.5 / 2, 1.5 / 2), (5.5 / 2, 1.5 / 2),
                     (5.5 / 2, 5.5 / 2)])
        ],
                                   shape=(3, 3, 3))
        assert_cbaois_equal(psoi_aug, expected)
Exemple #11
0
    def _test_augment_keypoints__kernel_size_differs(self, shape, shape_exp):
        from imgaug.augmentables.kps import Keypoint, KeypointsOnImage
        kps = [Keypoint(x=1.5, y=5.5), Keypoint(x=5.5, y=1.5)]
        kpsoi = KeypointsOnImage(kps, shape=shape)
        aug = self.augmenter((iap.Deterministic(3), iap.Deterministic(2)),
                             keep_size=False)

        kpsoi_aug = aug.augment_keypoints(kpsoi)

        expected = KeypointsOnImage.from_xy_array(np.float32([[
            (1.5 / shape[1]) * shape_exp[1], (5.5 / shape[0]) * shape_exp[0]
        ], [(5.5 / shape[1]) * shape_exp[1],
            (1.5 / shape[0]) * shape_exp[0]]]),
                                                  shape=shape_exp)
        assert_cbaois_equal(kpsoi_aug, expected)
Exemple #12
0
    def _test_augment_line_strings__kernel_size_differs(self, shape, shape_exp):
        from imgaug.augmentables.lines import LineString, LineStringsOnImage
        ls = [LineString([(1.5, 5.5), (5.5, 1.5), (5.5, 5.5)])]
        lsoi = LineStringsOnImage(ls, shape=shape)
        aug = self.augmenter(
            (iap.Deterministic(3), iap.Deterministic(2)),
            keep_size=False)

        lsoi_aug = aug.augment_line_strings(lsoi)

        expected = LineStringsOnImage(
            [LineString([
                ((1.5/shape[1])*shape_exp[1], (5.5/shape[0])*shape_exp[0]),
                ((5.5/shape[1])*shape_exp[1], (1.5/shape[0])*shape_exp[0]),
                ((5.5/shape[1])*shape_exp[1], (5.5/shape[0])*shape_exp[0])
            ])],
            shape=shape_exp)
        assert_cbaois_equal(lsoi_aug, expected)
Exemple #13
0
    def _test_augment_polygons__kernel_size_differs(self, shape, shape_exp):
        from imgaug.augmentables.polys import Polygon, PolygonsOnImage
        polys = [Polygon([(1.5, 5.5), (5.5, 1.5), (5.5, 5.5)])]
        psoi = PolygonsOnImage(polys, shape=shape)
        aug = self.augmenter(
            (iap.Deterministic(3), iap.Deterministic(2)),
            keep_size=False)

        psoi_aug = aug.augment_polygons(psoi)

        expected = PolygonsOnImage(
            [Polygon([
                ((1.5/shape[1])*shape_exp[1], (5.5/shape[0])*shape_exp[0]),
                ((5.5/shape[1])*shape_exp[1], (1.5/shape[0])*shape_exp[0]),
                ((5.5/shape[1])*shape_exp[1], (5.5/shape[0])*shape_exp[0])
            ])],
            shape=shape_exp)
        assert_cbaois_equal(psoi_aug, expected)
Exemple #14
0
    def _test_augment_bounding_boxes__kernel_size_differs(
            self, shape, shape_exp):
        from imgaug.augmentables.bbs import BoundingBox, BoundingBoxesOnImage
        bbs = [BoundingBox(x1=1.5, y1=2.5, x2=5.5, y2=6.5)]
        bbsoi = BoundingBoxesOnImage(bbs, shape=shape)
        aug = self.augmenter((iap.Deterministic(3), iap.Deterministic(2)),
                             keep_size=False)

        bbsoi_aug = aug.augment_bounding_boxes(bbsoi)

        expected = BoundingBoxesOnImage([
            BoundingBox(
                x1=(1.5 / shape[1]) * shape_exp[1],
                y1=(2.5 / shape[0]) * shape_exp[0],
                x2=(5.5 / shape[1]) * shape_exp[1],
                y2=(6.5 / shape[0]) * shape_exp[0],
            )
        ],
                                        shape=shape_exp)
        assert_cbaois_equal(bbsoi_aug, expected)
Exemple #15
0
 def _test_augment_cbaoi__kernel_size_is_noop(self, kernel_size, cbaoi,
                                              augf_name):
     aug = self.augmenter(kernel_size)
     cbaoi_aug = getattr(aug, augf_name)(cbaoi)
     assert_cbaois_equal(cbaoi_aug, cbaoi)
Exemple #16
0
 def _test_empty_cbaoi(self, cbaoi, augf_name):
     aug = self.augmenter(3, keep_size=False)
     cbaoi_aug = getattr(aug, augf_name)(cbaoi)
     expected = cbaoi.deepcopy()
     expected.shape = (2, 2, 3)
     assert_cbaois_equal(cbaoi_aug, expected)
Exemple #17
0
 def _test_augment_cbaoi__kernel_size_is_two__no_keep_size(
         self, cbaoi, expected, augf_name):
     aug = self.augmenter(2, keep_size=False)
     observed = getattr(aug, augf_name)(cbaoi)
     assert_cbaois_equal(observed, expected)