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


Python augmenters.Add方法代码示例

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


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

示例1: example_withchannels

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

    # fake RGB images
    images = np.random.randint(0, 255, (16, 128, 128, 3), dtype=np.uint8)

    # add a random value from the range (-30, 30) to the first two channels of
    # input images (e.g. to the R and G channels)
    aug = iaa.WithChannels(
      channels=[0, 1],
      children=iaa.Add((-30, 30))
    )

    images_aug = aug(images=images) 
开发者ID:aleju,项目名称:imgaug,代码行数:18,代码来源:check_readme_examples.py

示例2: main

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

    aug = iaa.WithColorspace(
        from_colorspace="RGB",
        to_colorspace="HSV",
        children=iaa.WithChannels(0, iaa.Add(50))
    )

    aug_no_colorspace = iaa.WithChannels(0, iaa.Add(50))

    img_show = np.hstack([
        image,
        aug.augment_image(image),
        aug_no_colorspace.augment_image(image)
    ])
    ia.imshow(img_show) 
开发者ID:aleju,项目名称:imgaug,代码行数:20,代码来源:check_withcolorspace.py

示例3: test_images_factor_is_tuple

# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import Add [as 别名]
def test_images_factor_is_tuple(self):
        image = np.zeros((1, 2, 1), dtype=np.uint8)
        nb_iterations = 1000
        aug = iaa.BlendAlpha((0.0, 1.0), iaa.Add(10), iaa.Add(110))
        values = []
        for _ in sm.xrange(nb_iterations):
            observed = aug.augment_image(image)
            observed_val = np.round(np.average(observed)) - 10
            values.append(observed_val / 100)

        nb_bins = 5
        hist, _ = np.histogram(values, bins=nb_bins, range=(0.0, 1.0),
                               density=False)
        density_expected = 1.0/nb_bins
        density_tolerance = 0.05
        for nb_samples in hist:
            density = nb_samples / nb_iterations
            assert np.isclose(density, density_expected,
                              rtol=0, atol=density_tolerance) 
开发者ID:aleju,项目名称:imgaug,代码行数:21,代码来源:test_blend.py

示例4: test_images_float_as_per_channel_tuple_as_factor_two_branches

# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import Add [as 别名]
def test_images_float_as_per_channel_tuple_as_factor_two_branches(self):
        aug = iaa.BlendAlpha(
            (0.0, 1.0),
            iaa.Add(100),
            iaa.Add(0),
            per_channel=0.5)
        seen = [0, 0]
        for _ in sm.xrange(200):
            observed = aug.augment_image(np.zeros((1, 1, 100), dtype=np.uint8))
            uq = np.unique(observed)
            if len(uq) == 1:
                seen[0] += 1
            elif len(uq) > 1:
                seen[1] += 1
            else:
                assert False
        assert 100 - 50 < seen[0] < 100 + 50
        assert 100 - 50 < seen[1] < 100 + 50 
开发者ID:aleju,项目名称:imgaug,代码行数:20,代码来源:test_blend.py

示例5: test_unusual_channel_numbers

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

        for shape in shapes:
            with self.subTest(shape=shape):
                image = np.full(shape, 0, dtype=np.uint8)
                aug = iaa.BlendAlpha(1.0, iaa.Add(1), iaa.Add(100))

                image_aug = aug(image=image)

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

示例6: test_hooks_limiting_propagation

# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import Add [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

示例7: test_zero_sized_axes

# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import Add [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 in shapes:
            with self.subTest(shape=shape):
                image = np.full(shape, 0, dtype=np.uint8)
                aug = iaa.BlendAlpha(1.0, iaa.Add(1), iaa.Add(100))

                image_aug = aug(image=image)

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

示例8: test_pickleable

# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import Add [as 别名]
def test_pickleable(self):
        shape = (15, 15, 3)
        iterations = 3
        augmenter = iaa.BlendAlphaBoundingBoxes(
            ["bb1", "bb2", "bb3"],
            foreground=iaa.Add((1, 10), seed=1),
            background=iaa.Add((11, 20), seed=2),
            nb_sample_labels=1,
            seed=3)
        image = np.mod(np.arange(int(np.prod(shape))), 256).astype(np.uint8)
        image = image.reshape(shape)
        bbs = [ia.BoundingBox(x1=1, y1=1, x2=5, y2=5, label="bb1"),
               ia.BoundingBox(x1=-3, y1=4, x2=20, y2=8, label="bb2")]

        augmenter_pkl = pickle.loads(pickle.dumps(augmenter, protocol=-1))

        for _ in np.arange(iterations):
            image_aug, bbs_aug = augmenter(
                image=image, bounding_boxes=[bbs])
            image_aug_pkl, bbs_aug_pkl = augmenter_pkl(
                image=image, bounding_boxes=[bbs])
            assert np.array_equal(image_aug, image_aug_pkl) 
开发者ID:aleju,项目名称:imgaug,代码行数:24,代码来源:test_blend.py

示例9: test_n

# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import Add [as 别名]
def test_n(self, mock_main, mock_initial):
        mock_main.return_value = [iaa.Add(1), iaa.Add(2), iaa.Add(4)]
        mock_initial.return_value = []

        img = np.zeros((1, 1, 3), dtype=np.uint8)
        expected = {
            0: [0],
            1: [1, 2, 4],
            2: [1+1, 1+2, 1+4, 2+2, 2+4, 4+4]
        }

        for n in [0, 1, 2]:
            with self.subTest(n=n):
                aug = iaa.RandAugment(n=n)
                img_aug = aug(image=img)
                assert img_aug[0, 0, 0] in expected[n]

    # for some reason these mocks don't work with
    # imgaug.augmenters.collections.(...) 
开发者ID:aleju,项目名称:imgaug,代码行数:21,代码来源:test_collections.py

示例10: __init__

# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import Add [as 别名]
def __init__(self):
        self.seq = iaa.Sequential([
            iaa.Sometimes(0.5, iaa.OneOf([
                iaa.GaussianBlur((0, 3.0)),  # blur images with a sigma between 0 and 3.0
                iaa.AverageBlur(k=(2, 7)),  # blur image using local means with kernel sizes between 2 and 7
                iaa.MedianBlur(k=(3, 11)),  # blur image using local medians with kernel sizes between 2 and 7
            ])),
            iaa.Sometimes(0.5, iaa.AdditiveGaussianNoise(loc=0, scale=(0.0, 0.05 * 255), per_channel=0.5)),
            iaa.Sometimes(0.5, iaa.Add((-10, 10), per_channel=0.5)),
            iaa.Sometimes(0.5, iaa.AddToHueAndSaturation((-20, 20))),
            iaa.Sometimes(0.5, iaa.FrequencyNoiseAlpha(
                exponent=(-4, 0),
                first=iaa.Multiply((0.5, 1.5), per_channel=True),
                second=iaa.LinearContrast((0.5, 2.0))
            )),
            iaa.Sometimes(0.5, iaa.PiecewiseAffine(scale=(0.01, 0.05))),
            iaa.Sometimes(0.5, iaa.PerspectiveTransform(scale=(0.01, 0.1)))
        ], random_order=True) 
开发者ID:WenmuZhou,项目名称:crnn.gluon,代码行数:20,代码来源:augment.py

示例11: __init__

# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import Add [as 别名]
def __init__(self, augmentation_rate):
        self.augs = iaa.Sometimes(
            augmentation_rate,
            iaa.SomeOf(
                (4, 7),
                [
                    iaa.Affine(rotate=(-10, 10)),
                    iaa.Fliplr(0.2),
                    iaa.AverageBlur(k=(2, 10)),
                    iaa.Add((-10, 10), per_channel=0.5),
                    iaa.Multiply((0.75, 1.25), per_channel=0.5),
                    iaa.ContrastNormalization((0.5, 2.0), per_channel=0.5),
                    iaa.Crop(px=(0, 20))
                ],
                random_order=True
            )
        ) 
开发者ID:Giphy,项目名称:celeb-detection-oss,代码行数:19,代码来源:img_augmentor.py

示例12: main

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

    aug = iaa.WithColorspace(
        from_colorspace="RGB",
        to_colorspace="HSV",
        children=iaa.WithChannels(0, iaa.Add(50))
    )

    aug_no_colorspace = iaa.WithChannels(0, iaa.Add(50))

    img_show = np.hstack([
        image,
        aug.augment_image(image),
        aug_no_colorspace.augment_image(image)
    ])
    misc.imshow(img_show) 
开发者ID:JoshuaPiinRueyPan,项目名称:ViolenceDetection,代码行数:20,代码来源:check_withcolorspace.py

示例13: example_withchannels

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

    # fake RGB images
    images = np.random.randint(0, 255, (16, 128, 128, 3), dtype=np.uint8)

    # add a random value from the range (-30, 30) to the first two channels of
    # input images (e.g. to the R and G channels)
    aug = iaa.WithChannels(
      channels=[0, 1],
      children=iaa.Add((-30, 30))
    )

    images_aug = aug.augment_images(images) 
开发者ID:JoshuaPiinRueyPan,项目名称:ViolenceDetection,代码行数:18,代码来源:test_readme_examples.py

示例14: __init__

# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import Add [as 别名]
def __init__(self,data_dir, back_dir,
                 batch_size=50,gan=True,imsize=128,
                 res_x=640,res_y=480,
                 **kwargs):
        '''
        data_dir: Folder that contains cropped image+xyz
        back_dir: Folder that contains random background images
            batch_size: batch size for training
        gan: if False, gt for GAN is not yielded
        '''
        self.data_dir = data_dir
        self.back_dir = back_dir
        self.imsize=imsize
        self.batch_size = batch_size
        self.gan = gan
        self.backfiles = os.listdir(back_dir)
        data_list = os.listdir(data_dir)
        self.datafiles=[]
        self.res_x=res_x
        self.res_y=res_y

        for file in data_list:
            if(file.endswith(".npy")):
                self.datafiles.append(file)

        self.n_data = len(self.datafiles)
        self.n_background = len(self.backfiles)
        print("Total training views:", self.n_data)

        self.seq_syn= iaa.Sequential([
                                    iaa.WithChannels(0, iaa.Add((-15, 15))),
                                    iaa.WithChannels(1, iaa.Add((-15, 15))),
                                    iaa.WithChannels(2, iaa.Add((-15, 15))),
                                    iaa.ContrastNormalization((0.8, 1.3)),
                                    iaa.Multiply((0.8, 1.2),per_channel=0.5),
                                    iaa.GaussianBlur(sigma=(0.0, 0.5)),
                                    iaa.Sometimes(0.1, iaa.AdditiveGaussianNoise(scale=10, per_channel=True)),
                                    iaa.Sometimes(0.5, iaa.ContrastNormalization((0.5, 2.2), per_channel=0.3)),
                                    ], random_order=True) 
开发者ID:kirumang,项目名称:Pix2Pose,代码行数:41,代码来源:data_io.py

示例15: main

# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import Add [as 别名]
def main():
    image = ia.quokka_square(size=(128, 128))
    images = []

    for i in range(15):
        aug = iaa.WithHueAndSaturation(iaa.WithChannels(0, iaa.Add(i*20)))
        images.append(aug.augment_image(image))

    for i in range(15):
        aug = iaa.WithHueAndSaturation(iaa.WithChannels(1, iaa.Add(i*20)))
        images.append(aug.augment_image(image))

    ia.imshow(ia.draw_grid(images, rows=2)) 
开发者ID:aleju,项目名称:imgaug,代码行数:15,代码来源:check_with_hue_and_saturation.py


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