当前位置: 首页>>代码示例>>Python>>正文


Python augmenters.Superpixels方法代码示例

本文整理汇总了Python中imgaug.augmenters.Superpixels方法的典型用法代码示例。如果您正苦于以下问题:Python augmenters.Superpixels方法的具体用法?Python augmenters.Superpixels怎么用?Python augmenters.Superpixels使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在imgaug.augmenters的用法示例。


在下文中一共展示了augmenters.Superpixels方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import Superpixels [as 别名]
def main():
    image = data.astronaut()[..., ::-1]  # rgb2bgr
    print(image.shape)

    cv2.namedWindow("aug", cv2.WINDOW_NORMAL)
    cv2.imshow("aug", image)
    cv2.waitKey(TIME_PER_STEP)

    for n_segments in cycle(reversed(np.arange(1, 200, SEGMENTS_PER_STEP))):
        aug = iaa.Superpixels(p_replace=0.75, n_segments=n_segments)
        time_start = time.time()
        img_aug = aug.augment_image(image)
        print("augmented %d in %.4fs" % (n_segments, time.time() - time_start))
        img_aug = ia.draw_text(img_aug, x=5, y=5, text="%d" % (n_segments,))

        cv2.imshow("aug", img_aug)
        cv2.waitKey(TIME_PER_STEP) 
开发者ID:aleju,项目名称:imgaug,代码行数:19,代码来源:check_superpixels.py

示例2: test_zero_sized_axes

# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import Superpixels [as 别名]
def test_zero_sized_axes(self):
        shapes = [
            (0, 0),
            (0, 1),
            (1, 0),
            (0, 1, 0),
            (1, 0, 0),
            (0, 1, 1),
            (1, 0, 1)
        ]

        for shape, use_np_replace in itertools.product(shapes, _NP_REPLACE):
            with self.subTest(shape=shape, use_np_replace=use_np_replace):
                with _create_replace_np_context(use_np_replace):
                    image = np.full(shape, 128, dtype=np.uint8)
                    aug = iaa.Superpixels(p_replace=1.0, n_segments=10)

                    image_aug = aug(image=image)

                    assert image_aug.dtype.name == "uint8"
                    assert image_aug.shape == shape 
开发者ID:aleju,项目名称:imgaug,代码行数:23,代码来源:test_segmentation.py

示例3: test_unusual_channel_numbers

# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import Superpixels [as 别名]
def test_unusual_channel_numbers(self):
        shapes = [
            (1, 1, 4),
            (1, 1, 5),
            (1, 1, 512),
            (1, 1, 513)
        ]

        for shape, use_np_replace in itertools.product(shapes, _NP_REPLACE):
            with self.subTest(shape=shape, use_np_replace=use_np_replace):
                with _create_replace_np_context(use_np_replace):
                    image = np.full(shape, 128, dtype=np.uint8)
                    aug = iaa.Superpixels(p_replace=1.0, n_segments=10)

                    image_aug = aug(image=image)

                    assert image_aug.dtype.name == "uint8"
                    assert image_aug.shape == shape 
开发者ID:aleju,项目名称:imgaug,代码行数:20,代码来源:test_segmentation.py

示例4: main

# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import Superpixels [as 别名]
def main():
    image = data.astronaut()[...,::-1] # rgb2bgr
    print(image.shape)

    cv2.namedWindow("aug", cv2.WINDOW_NORMAL)
    cv2.imshow("aug", image)
    cv2.waitKey(TIME_PER_STEP)

    for n_segments in cycle(reversed(np.arange(1, 200, SEGMENTS_PER_STEP))):
        aug = iaa.Superpixels(p_replace=0.75, n_segments=n_segments)
        time_start = time.time()
        img_aug = aug.augment_image(image)
        print("augmented %d in %.4fs" % (n_segments, time.time() - time_start))
        img_aug = ia.draw_text(img_aug, x=5, y=5, text="%d" % (n_segments,))

        cv2.imshow("aug", img_aug)
        cv2.waitKey(TIME_PER_STEP) 
开发者ID:JoshuaPiinRueyPan,项目名称:ViolenceDetection,代码行数:19,代码来源:check_superpixels.py

示例5: test_p_replace_0_n_segments_2

# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import Superpixels [as 别名]
def test_p_replace_0_n_segments_2(self):
        for use_np_replace in _NP_REPLACE:
            with self.subTest(use_np_replace=use_np_replace):
                with _create_replace_np_context(use_np_replace):
                    aug = iaa.Superpixels(p_replace=0, n_segments=2)
                    observed = aug.augment_image(self.base_img)
                    expected = self.base_img
                    assert np.allclose(observed, expected) 
开发者ID:aleju,项目名称:imgaug,代码行数:10,代码来源:test_segmentation.py

示例6: test_p_replace_1_n_segments_2

# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import Superpixels [as 别名]
def test_p_replace_1_n_segments_2(self):
        for use_np_replace in _NP_REPLACE:
            with self.subTest(use_np_replace=use_np_replace):
                with _create_replace_np_context(use_np_replace):
                    aug = iaa.Superpixels(p_replace=1.0, n_segments=2)
                    observed = aug.augment_image(self.base_img)
                    expected = self.base_img_superpixels
                    assert self._array_equals_tolerant(observed, expected, 2) 
开发者ID:aleju,项目名称:imgaug,代码行数:10,代码来源:test_segmentation.py

示例7: test_p_replace_1_n_segments_stochastic_parameter

# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import Superpixels [as 别名]
def test_p_replace_1_n_segments_stochastic_parameter(self):
        for use_np_replace in _NP_REPLACE:
            with self.subTest(use_np_replace=use_np_replace):
                with _create_replace_np_context(use_np_replace):
                    aug = iaa.Superpixels(
                        p_replace=1.0, n_segments=iap.Deterministic(2)
                    )
                    observed = aug.augment_image(self.base_img)
                    expected = self.base_img_superpixels
                    assert self._array_equals_tolerant(observed, expected, 2) 
开发者ID:aleju,项目名称:imgaug,代码行数:12,代码来源:test_segmentation.py

示例8: test_p_replace_stochastic_parameter_n_segments_2

# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import Superpixels [as 别名]
def test_p_replace_stochastic_parameter_n_segments_2(self):
        for use_np_replace in _NP_REPLACE:
            with self.subTest(use_np_replace=use_np_replace):
                with _create_replace_np_context(use_np_replace):
                    aug = iaa.Superpixels(
                        p_replace=iap.Binomial(iap.Choice([0.0, 1.0])),
                        n_segments=2
                    )
                    observed = aug.augment_image(self.base_img)
                    assert (
                        np.allclose(observed, self.base_img)
                        or self._array_equals_tolerant(
                            observed, self.base_img_superpixels, 2)
                    ) 
开发者ID:aleju,项目名称:imgaug,代码行数:16,代码来源:test_segmentation.py

示例9: test_failure_on_invalid_datatype_for_p_replace

# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import Superpixels [as 别名]
def test_failure_on_invalid_datatype_for_p_replace(self):
        # note that assertRaisesRegex does not exist in 2.7
        got_exception = False
        try:
            _ = iaa.Superpixels(p_replace="test", n_segments=100)
        except Exception as exc:
            assert "Expected " in str(exc)
            got_exception = True
        assert got_exception 
开发者ID:aleju,项目名称:imgaug,代码行数:11,代码来源:test_segmentation.py

示例10: test_failure_on_invalid_datatype_for_n_segments

# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import Superpixels [as 别名]
def test_failure_on_invalid_datatype_for_n_segments(self):
        # note that assertRaisesRegex does not exist in 2.7
        got_exception = False
        try:
            _ = iaa.Superpixels(p_replace=1, n_segments="test")
        except Exception as exc:
            assert "Expected " in str(exc)
            got_exception = True
        assert got_exception 
开发者ID:aleju,项目名称:imgaug,代码行数:11,代码来源:test_segmentation.py

示例11: test_get_parameters

# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import Superpixels [as 别名]
def test_get_parameters(self):
        aug = iaa.Superpixels(
            p_replace=0.5, n_segments=2, max_size=100, interpolation="nearest")
        params = aug.get_parameters()
        assert params[0] is aug.p_replace
        assert is_parameter_instance(params[0].p, iap.Deterministic)
        assert params[1] is aug.n_segments
        assert 0.5 - 1e-4 < params[0].p.value < 0.5 + 1e-4
        assert params[1].value == 2
        assert params[2] == 100
        assert params[3] == "nearest" 
开发者ID:aleju,项目名称:imgaug,代码行数:13,代码来源:test_segmentation.py

示例12: test_other_dtypes_float

# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import Superpixels [as 别名]
def test_other_dtypes_float(self):
        # currently, no float dtype is actually accepted
        for dtype in []:
            def _allclose(a, b):
                atol = 1e-4 if dtype == np.float16 else 1e-8
                return np.allclose(a, b, atol=atol, rtol=0)

            isize = np.dtype(dtype).itemsize
            for value in [0, 1.0, 10.0, 1000 ** (isize - 1)]:
                v1 = (-1) * value
                v2 = value

                aug = iaa.Superpixels(p_replace=1.0, n_segments=2)
                img = np.array([
                    [v1, v1, v2, v2],
                    [v1, v1, v2, v2]
                ], dtype=dtype)
                img_aug = aug.augment_image(img)
                assert img_aug.dtype == np.dtype(dtype)
                assert _allclose(img_aug, img)

                aug = iaa.Superpixels(p_replace=1.0, n_segments=1)
                img = np.array([
                    [v2, v2, v2, v2],
                    [v1, v2, v2, v2]
                ], dtype=dtype)
                img_aug = aug.augment_image(img)
                assert img_aug.dtype == np.dtype(dtype)
                assert _allclose(img_aug, (7/8)*v2 + (1/8)*v1) 
开发者ID:aleju,项目名称:imgaug,代码行数:31,代码来源:test_segmentation.py

示例13: test_pickleable

# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import Superpixels [as 别名]
def test_pickleable(self):
        aug = iaa.Superpixels(p_replace=0.5, seed=1)
        runtest_pickleable_uint8_img(aug, iterations=10, shape=(25, 25, 1)) 
开发者ID:aleju,项目名称:imgaug,代码行数:5,代码来源:test_segmentation.py

示例14: __init__

# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import Superpixels [as 别名]
def __init__(self, p_replace=0.1, n_segments=100, prob=0.5):
        super().__init__(prob)
        self.processor = iaa.Superpixels(p_replace=p_replace, n_segments=n_segments) 
开发者ID:selimsef,项目名称:dsb2018_topcoders,代码行数:5,代码来源:transforms.py

示例15: chapter_augmenters_superpixels

# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import Superpixels [as 别名]
def chapter_augmenters_superpixels():
    aug = iaa.Superpixels(p_replace=0.5, n_segments=64)
    run_and_save_augseq(
        "superpixels_50_64.jpg", aug,
        [ia.quokka(size=(128, 128)) for _ in range(8)], cols=4, rows=2
    )

    aug = iaa.Superpixels(p_replace=(0.1, 1.0), n_segments=(16, 128))
    run_and_save_augseq(
        "superpixels.jpg", aug,
        [ia.quokka(size=(128, 128)) for _ in range(8)], cols=4, rows=2
    )

    #ps = [1/8*i for i in range(8)]
    ps = np.linspace(0, 1.0, num=8)
    run_and_save_augseq(
        "superpixels_vary_p.jpg",
        [iaa.Superpixels(p_replace=p, n_segments=64) for p in ps],
        [ia.quokka(size=(64, 64)) for _ in range(8)], cols=8, rows=1,
        quality=75
    )

    ns = [16*i for i in range(1, 9)]
    run_and_save_augseq(
        "superpixels_vary_n.jpg",
        [iaa.Superpixels(p_replace=1.0, n_segments=n) for n in ns],
        [ia.quokka(size=(64, 64)) for _ in range(8)], cols=8, rows=1,
        quality=75
    ) 
开发者ID:JoshuaPiinRueyPan,项目名称:ViolenceDetection,代码行数:31,代码来源:generate_documentation_images.py


注:本文中的imgaug.augmenters.Superpixels方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。