def main():
    aug = iaa.BlendAlphaMask(
        iaa.SomeColorsMaskGen(),
        iaa.OneOf([iaa.TotalDropout(1.0),
                   iaa.AveragePooling(8)]))

    aug2 = iaa.BlendAlphaSomeColors(
        iaa.OneOf([iaa.TotalDropout(1.0),
                   iaa.AveragePooling(8)]))

    urls = [
        ("https://upload.wikimedia.org/wikipedia/commons/thumb/4/43/"
         "Sarcophilus_harrisii_taranna.jpg/"
         "320px-Sarcophilus_harrisii_taranna.jpg"),
        ("https://upload.wikimedia.org/wikipedia/commons/thumb/b/ba/"
         "Vincent_van_Gogh_-_Wheatfield_with_crows_-_Google_Art_Project.jpg/"
         "320px-Vincent_van_Gogh_-_Wheatfield_with_crows_-_Google_Art_Project"
         ".jpg"),
        ("https://upload.wikimedia.org/wikipedia/commons/thumb/0/0c/"
         "Galerella_sanguinea_Zoo_Praha_2011-2.jpg/207px-Galerella_sanguinea_"
         "Zoo_Praha_2011-2.jpg"),
        ("https://upload.wikimedia.org/wikipedia/commons/thumb/9/96/"
         "Ambrosius_Bosschaert_the_Elder_%28Dutch_-_Flower_Still_Life_-_"
         "Google_Art_Project.jpg/307px-Ambrosius_Bosschaert_the_Elder_%28"
         "Dutch_-_Flower_Still_Life_-_Google_Art_Project.jpg")
    ]

    for url in urls:
        img = imageio.imread(url)
        ia.imshow(ia.draw_grid(aug(images=[img] * 25), cols=5, rows=5))
        ia.imshow(ia.draw_grid(aug2(images=[img] * 25), cols=5, rows=5))
Exemplo n.º 2
0
def chapter_augmenters_blendalphamask():
    fn_start = "blend/blendalphamask"

    aug = iaa.BlendAlphaMask(
        iaa.InvertMaskGen(0.5, iaa.VerticalLinearGradientMaskGen()),
        iaa.Sequential(
            [iaa.Clouds(),
             iaa.WithChannels([1, 2], iaa.Multiply(0.5))]))
    run_and_save_augseq(fn_start + ".jpg",
                        aug,
                        [ia.quokka(size=(128, 128)) for _ in range(4 * 2)],
                        cols=4,
                        rows=2)
def main():
    aug = iaa.BlendAlphaMask(
        iaa.SegMapClassIdsMaskGen(1),
        iaa.OneOf([iaa.TotalDropout(1.0),
                   iaa.AveragePooling(8)]))

    aug2 = iaa.BlendAlphaSegMapClassIds(
        1, iaa.OneOf([iaa.TotalDropout(1.0),
                      iaa.AveragePooling(8)]))

    image = ia.quokka(0.25)
    segmap = ia.quokka_segmentation_map(0.25)

    images_aug, segmaps_aug = aug(images=[image] * 25,
                                  segmentation_maps=[segmap] * 25)
    ia.imshow(ia.draw_grid(images_aug, cols=5, rows=5))

    images_aug, segmaps_aug = aug2(images=[image] * 25,
                                   segmentation_maps=[segmap] * 25)
    ia.imshow(ia.draw_grid(images_aug, cols=5, rows=5))
Exemplo n.º 4
0
aug20 = iaa.GaussianBlur(sigma=(0.0, 3.0)) # blur
aug21 = iaa.AverageBlur(k=((1, 5), (1, 3)))

aug22 = iaa.MotionBlur(k=3)

# aug23 = iaa.BlendAlpha(
#     (0.0, 0.5),
#     iaa.Affine(rotate=(0, 0)),
#     per_channel=0.5)
# aug24 = iaa.BlendAlpha(
#     (0.0, 0.5),
#     foreground=iaa.Add(60),
#     background=iaa.Multiply(0.2))

aug25 = iaa.BlendAlphaMask(
    iaa.InvertMaskGen(0.5, iaa.VerticalLinearGradientMaskGen()),
    iaa.Clouds()
)

aug26 = iaa.BlendAlphaElementwise(
    (0.0, 0.5),
    iaa.Affine(rotate=(-0, 0)),
    per_channel=0.5)

aug27 = iaa.BlendAlphaElementwise(
    (0.0, 0.2),
    foreground=iaa.Add(20),
    background=iaa.Multiply(0.4))
aug28 = iaa.BlendAlphaElementwise([0.25, 0.75], iaa.MedianBlur(13))

aug29 = iaa.BlendAlphaSimplexNoise(iaa.EdgeDetect(0.6))
aug30 = iaa.BlendAlphaSimplexNoise(
            count += 1
            print("{} annotations and images have been transformed!!".format(
                count))


sometimes = lambda aug: iaa.Sometimes(0.9, aug)

seq = iaa.SomeOf(
    (1, 2),
    [
        sometimes(
            iaa.BlendAlphaFrequencyNoise(foreground=iaa.EdgeDetect(0.75),
                                         upscale_method="nearest")),
        sometimes(
            iaa.BlendAlphaMask(
                iaa.InvertMaskGen(0.5, iaa.VerticalLinearGradientMaskGen()),
                iaa.Sequential([iaa.Clouds(),
                                iaa.WithChannels([1, 2])]))),
        sometimes(
            iaa.BlendAlphaCheckerboard(
                nb_rows=2, nb_cols=(1, 4), foreground=iaa.AddToHue(
                    (-80, 80)))),

        #important augmenter
        sometimes(
            iaa.BlendAlphaVerticalLinearGradient(iaa.AveragePooling(10),
                                                 start_at=(0.0, 1.0),
                                                 end_at=(0.0, 1.0))),
        sometimes(
            iaa.BlendAlphaSimplexNoise(iaa.EdgeDetect(1.0),
                                       upscale_method="linear"))
    ])