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


Python imgaug.HooksImages方法代码示例

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


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

示例1: test_hooks_limiting_propagation

# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import HooksImages [as 别名]
def test_hooks_limiting_propagation(self):
        aug = iaa.BlendAlphaElementwise(
            0.5,
            iaa.Add(100),
            iaa.Add(50),
            name="AlphaElementwiseTest")

        def propagator(images, augmenter, parents, default):
            if "AlphaElementwise" in augmenter.name:
                return False
            else:
                return default

        hooks = ia.HooksImages(propagator=propagator)
        image = np.zeros((10, 10, 3), dtype=np.uint8) + 10
        observed = aug.augment_image(image, hooks=hooks)
        assert np.array_equal(observed, image) 
开发者ID:aleju,项目名称:imgaug,代码行数:19,代码来源:test_blend.py

示例2: data_augment

# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import HooksImages [as 别名]
def data_augment(self, image, mask, augmentation):
        # Augmentation
        # This requires the imgaug lib (https://github.com/aleju/imgaug)
        if augmentation:
            import imgaug
            # Augmenters that are safe to apply to masks
            # Some, such as Affine, have settings that make them unsafe, so always
            # test your augmentation on masks
            MASK_AUGMENTERS = ["Sequential", "SomeOf", "OneOf", "Sometimes",
                               "Fliplr", "Flipud", "CropAndPad",
                               "Affine", "PiecewiseAffine"]

            def hook(images, augmenter, parents, default):
                """Determines which augmenters to apply to masks."""
                return augmenter.__class__.__name__ in MASK_AUGMENTERS

            # Store shapes before augmentation to compare
            image_shape = image.shape
            mask_shape = mask.shape
            # Make augmenters deterministic to apply similarly to images and masks
            det = augmentation.to_deterministic()
            # image should be uint8!!
            images = det.augment_image(image)
            # Change mask to np.uint8 because imgaug doesn't support np.bool
            masks = det.augment_image(mask.astype(np.uint8),
                                       hooks=imgaug.HooksImages(activator=hook))
            # Verify that shapes didn't change
            assert images.shape == image_shape, "Augmentation shouldn't change image size"
            assert masks.shape == mask_shape, "Augmentation shouldn't change mask size"
            # Change mask back to bool
            # masks = masks.astype(np.bool)
        return image, mask 
开发者ID:JohnleeHIT,项目名称:Brats2019,代码行数:34,代码来源:utils.py

示例3: test_propagation_hooks_ctx

# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import HooksImages [as 别名]
def test_propagation_hooks_ctx(self):
        def propagator(images, augmenter, parents, default):
            if ia.is_np_array(images):
                return False
            else:
                return True

        hooks = ia.HooksImages(propagator=propagator)

        batch = _BatchInAugmentation(
            images=np.zeros((3, 3, 4, 1), dtype=np.uint8),
            keypoints=[
                ia.KeypointsOnImage(
                    [ia.Keypoint(0, 0)],
                    shape=(3, 4, 1)
                ),
                ia.KeypointsOnImage(
                    [ia.Keypoint(1, 1)],
                    shape=(3, 4, 1)
                ),
                ia.KeypointsOnImage(
                    [ia.Keypoint(2, 2)],
                    shape=(3, 4, 1)
                )
            ]
        )

        with batch.propagation_hooks_ctx(iaa.Identity(), hooks, []) \
                as batch_prop:
            assert batch_prop.images is None
            assert batch_prop.keypoints is not None
            assert len(batch_prop.keypoints) == 3

            batch_prop.keypoints[0].keypoints[0].x = 10

        assert batch.images is not None
        assert batch.keypoints is not None
        assert batch.keypoints[0].keypoints[0].x == 10 
开发者ID:aleju,项目名称:imgaug,代码行数:40,代码来源:test_batches.py

示例4: test_using_hooks_to_deactivate_propagation

# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import HooksImages [as 别名]
def test_using_hooks_to_deactivate_propagation(self):
        def _propagator(images, augmenter, parents, default):
            return False if augmenter.name == "foo" else default

        aug = iaa.WithBrightnessChannels(
            children=iaa.Add(100),
            to_colorspace=iaa.CSPACE_HSV,
            name="foo")
        image = np.arange(6*6*3).astype(np.uint8).reshape((6, 6, 3))

        image_aug = aug(image=image,
                        hooks=ia.HooksImages(propagator=_propagator))

        assert np.array_equal(image_aug, image) 
开发者ID:aleju,项目名称:imgaug,代码行数:16,代码来源:test_color.py

示例5: example_hooks

# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import HooksImages [as 别名]
def example_hooks():
    print("Example: Hooks")
    import imgaug as ia
    from imgaug import augmenters as iaa
    import numpy as np

    # images and heatmaps, just arrays filled with value 30
    images = np.ones((16, 128, 128, 3), dtype=np.uint8) * 30
    heatmaps = np.ones((16, 128, 128, 21), dtype=np.uint8) * 30

    # add vertical lines to see the effect of flip
    images[:, 16:128-16, 120:124, :] = 120
    heatmaps[:, 16:128-16, 120:124, :] = 120

    seq = iaa.Sequential([
      iaa.Fliplr(0.5, name="Flipper"),
      iaa.GaussianBlur((0, 3.0), name="GaussianBlur"),
      iaa.Dropout(0.02, name="Dropout"),
      iaa.AdditiveGaussianNoise(scale=0.01*255, name="MyLittleNoise"),
      iaa.AdditiveGaussianNoise(loc=32, scale=0.0001*255, name="SomeOtherNoise"),
      iaa.Affine(translate_px={"x": (-40, 40)}, name="Affine")
    ])

    # change the activated augmenters for heatmaps
    def activator_heatmaps(images, augmenter, parents, default):
        if augmenter.name in ["GaussianBlur", "Dropout", "MyLittleNoise"]:
            return False
        else:
            # default value for all other augmenters
            return default
    hooks_heatmaps = ia.HooksImages(activator=activator_heatmaps)

    seq_det = seq.to_deterministic() # call this for each batch again, NOT only once at the start
    images_aug = seq_det.augment_images(images)
    heatmaps_aug = seq_det.augment_images(heatmaps, hooks=hooks_heatmaps)

    # -----------
    ia.show_grid(images_aug)
    ia.show_grid(heatmaps_aug[..., 0:3]) 
开发者ID:JoshuaPiinRueyPan,项目名称:ViolenceDetection,代码行数:41,代码来源:test_readme_examples.py

示例6: data_augment_volume

# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import HooksImages [as 别名]
def data_augment_volume(self, *datalist , augmentation):

        # first get the volume data from the data list
        image1, image2, image3, mask1, mask2, mask3 = datalist
        # Augmentation
        # This requires the imgaug lib (https://github.com/aleju/imgaug)
        if augmentation:
            import imgaug
            # Augmenters that are safe to apply to masks
            # Some, such as Affine, have settings that make them unsafe, so always
            # test your augmentation on masks
            MASK_AUGMENTERS = ["Sequential", "SomeOf", "OneOf", "Sometimes",
                               "Fliplr", "Flipud", "CropAndPad",
                               "Affine", "PiecewiseAffine"]

            def hook(images, augmenter, parents, default):
                """Determines which augmenters to apply to masks."""
                return augmenter.__class__.__name__ in MASK_AUGMENTERS

            # Store shapes before augmentation to compare
            image1_shape = image1.shape
            mask1_shape = mask1.shape
            image2_shape = image2.shape
            mask2_shape = mask2.shape
            image3_shape = image3.shape
            mask3_shape = mask3.shape
            # Make augmenters deterministic to apply similarly to images and masks
            det = augmentation.to_deterministic()
            # image should be uint8!!
            image1 = det.augment_image(image1)
            image2 = det.augment_image(image2)
            image3 = det.augment_image(image3)
            # Change mask to np.uint8 because imgaug doesn't support np.bool
            mask1 = det.augment_image(mask1.astype(np.uint8),
                                       hooks=imgaug.HooksImages(activator=hook))
            mask2 = det.augment_image(mask2.astype(np.uint8),
                                      hooks=imgaug.HooksImages(activator=hook))
            mask3 = det.augment_image(mask3.astype(np.uint8),
                                      hooks=imgaug.HooksImages(activator=hook))
            # Verify that shapes didn't change
            assert image1.shape == image1_shape, "Augmentation shouldn't change image size"
            assert mask1.shape == mask1_shape, "Augmentation shouldn't change mask size"
            assert image2.shape == image2_shape, "Augmentation shouldn't change image size"
            assert mask2.shape == mask2_shape, "Augmentation shouldn't change mask size"
            assert image3.shape == image3_shape, "Augmentation shouldn't change image size"
            assert mask3.shape == mask3_shape, "Augmentation shouldn't change mask size"
            # Change mask back to bool
            # masks = masks.astype(np.bool)
        return image1,image2, image3, mask1, mask2, mask3 
开发者ID:JohnleeHIT,项目名称:Brats2019,代码行数:51,代码来源:utils.py

示例7: example_hooks

# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import HooksImages [as 别名]
def example_hooks():
    print("Example: Hooks")
    import numpy as np
    import imgaug as ia
    import imgaug.augmenters as iaa

    # Images and heatmaps, just arrays filled with value 30.
    # We define the heatmaps here as uint8 arrays as we are going to feed them
    # through the pipeline similar to normal images. In that way, every
    # augmenter is applied to them.
    images = np.full((16, 128, 128, 3), 30, dtype=np.uint8)
    heatmaps = np.full((16, 128, 128, 21), 30, dtype=np.uint8)

    # add vertical lines to see the effect of flip
    images[:, 16:128-16, 120:124, :] = 120
    heatmaps[:, 16:128-16, 120:124, :] = 120

    seq = iaa.Sequential([
      iaa.Fliplr(0.5, name="Flipper"),
      iaa.GaussianBlur((0, 3.0), name="GaussianBlur"),
      iaa.Dropout(0.02, name="Dropout"),
      iaa.AdditiveGaussianNoise(scale=0.01*255, name="MyLittleNoise"),
      iaa.AdditiveGaussianNoise(loc=32, scale=0.0001*255, name="SomeOtherNoise"),
      iaa.Affine(translate_px={"x": (-40, 40)}, name="Affine")
    ])

    # change the activated augmenters for heatmaps,
    # we only want to execute horizontal flip, affine transformation and one of
    # the gaussian noises
    def activator_heatmaps(images, augmenter, parents, default):
        if augmenter.name in ["GaussianBlur", "Dropout", "MyLittleNoise"]:
            return False
        else:
            # default value for all other augmenters
            return default
    hooks_heatmaps = ia.HooksImages(activator=activator_heatmaps)

    # call to_deterministic() once per batch, NOT only once at the start
    seq_det = seq.to_deterministic()
    images_aug = seq_det(images=images)
    heatmaps_aug = seq_det(images=heatmaps, hooks=hooks_heatmaps)

    # -----------
    ia.show_grid(images_aug)
    ia.show_grid(heatmaps_aug[..., 0:3]) 
开发者ID:aleju,项目名称:imgaug,代码行数:47,代码来源:check_readme_examples.py


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