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


Python augmenters.PerspectiveTransform方法代码示例

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


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

示例1: __init__

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

示例2: amaugimg

# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import PerspectiveTransform [as 别名]
def amaugimg(image):
    #数据增强
    image = cv2.cvtColor(np.asarray(image), cv2.COLOR_RGB2BGR)

    seq = iaa.Sequential([
        # iaa.Affine(rotate=(-5, 5),
        #            shear=(-5, 5),
        #            mode='edge'),

        iaa.SomeOf((0, 2),                        #选择数据增强
                   [
                       iaa.GaussianBlur((0, 1.5)),
                       iaa.AdditiveGaussianNoise(loc=0, scale=(0.0, 0.01 * 255), per_channel=0.5),
                       # iaa.AddToHueAndSaturation((-5, 5)),  # change hue and saturation
                       iaa.PiecewiseAffine(scale=(0.01, 0.03)),
                       iaa.PerspectiveTransform(scale=(0.01, 0.1))
                   ],
                   random_order=True
                   )
    ])
    image = seq.augment_image(image)

    image = Image.fromarray(cv2.cvtColor(image, cv2.COLOR_BGR2RGB))
    return image 
开发者ID:LcenArthas,项目名称:CVWC2019-Amur-Tiger-Re-ID,代码行数:26,代码来源:dataset_loader.py

示例3: main

# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import PerspectiveTransform [as 别名]
def main():
    nb_checked = 0

    augs = iaa.SomeOf((1, None), [
        iaa.Resize({"height": (1, 100), "width": (1, 100)}),
        iaa.Affine(
            scale=(0.01, 2.0),
            rotate=(-360, 360),
            shear=(-360, 360),
            translate_px={"x": (-50, 50), "y": (-50, 50)}
        ),
        iaa.PerspectiveTransform((0.01, 0.2))
    ])

    height, width = 100, 200

    while True:
        poly = create_random_polygon(height, width, nb_checked)
        psoi = PolygonsOnImage([poly], shape=(height, width, 3))
        psoi_aug = augs.augment_polygons(psoi)

        if not poly.is_valid or not psoi_aug.polygons[0].is_valid:
            print("poly:     ", poly, poly.is_valid)
            print("poly_aug: ", psoi_aug.polygons[0], psoi_aug.polygons[0].is_valid)

        assert poly.is_valid
        assert psoi_aug.polygons[0].is_valid

        nb_checked += 1
        if nb_checked % 100 == 0:
            print("Checked %d..." % (nb_checked,))
        if nb_checked > 100000:
            break 
开发者ID:aleju,项目名称:imgaug,代码行数:35,代码来源:check_polygons_stay_valid_during_augmentation.py

示例4: __init__

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

示例5: aug_on_fly

# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import PerspectiveTransform [as 别名]
def aug_on_fly(img, det_mask, cls_mask):
    """Do augmentation with different combination on each training batch
    """
    def image_basic_augmentation(image, masks, ratio_operations=0.9):
        # without additional operations
        # according to the paper, operations such as shearing, fliping horizontal/vertical,
        # rotating, zooming and channel shifting will be apply
        sometimes = lambda aug: iaa.Sometimes(ratio_operations, aug)
        hor_flip_angle = np.random.uniform(0, 1)
        ver_flip_angle = np.random.uniform(0, 1)
        seq = iaa.Sequential([
            sometimes(
                iaa.SomeOf((0, 5), [
                iaa.Fliplr(hor_flip_angle),
                iaa.Flipud(ver_flip_angle),
                iaa.Affine(shear=(-16, 16)),
                iaa.Affine(scale={'x': (1, 1.6), 'y': (1, 1.6)}),
                iaa.PerspectiveTransform(scale=(0.01, 0.1))
            ]))
        ])
        det_mask, cls_mask = masks[0], masks[1]
        seq_to_deterministic = seq.to_deterministic()
        aug_img = seq_to_deterministic.augment_images(image)
        aug_det_mask = seq_to_deterministic.augment_images(det_mask)
        aug_cls_mask = seq_to_deterministic.augment_images(cls_mask)
        return aug_img, aug_det_mask, aug_cls_mask

    aug_image, aug_det_mask, aug_cls_mask = image_basic_augmentation(image=img, masks=[det_mask, cls_mask])
    return aug_image, aug_det_mask, aug_cls_mask 
开发者ID:zhuyiche,项目名称:sfcn-opi,代码行数:31,代码来源:util.py

示例6: processor

# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import PerspectiveTransform [as 别名]
def processor(self):
        return iaa.PerspectiveTransform(self.scale, keep_size=self.keep_size) 
开发者ID:albumentations-team,项目名称:albumentations,代码行数:4,代码来源:transforms.py

示例7: get_perspective_transform_sequence

# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import PerspectiveTransform [as 别名]
def get_perspective_transform_sequence(sigma):
    return iaa.Sequential([iaa.PerspectiveTransform(scale=(float(sigma/10), sigma), deterministic=True)], deterministic=True) 
开发者ID:nicolefinnie,项目名称:kaggle-dsb2018,代码行数:4,代码来源:augment.py

示例8: main

# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import PerspectiveTransform [as 别名]
def main():
    image = ia.data.quokka(size=0.5)
    kps = [ia.KeypointsOnImage(
        [ia.Keypoint(x=245, y=203), ia.Keypoint(x=365, y=195), ia.Keypoint(x=313, y=269)],
        shape=(image.shape[0]*2, image.shape[1]*2)
    )]
    kps[0] = kps[0].on(image.shape)
    print("image shape:", image.shape)

    augs = [
        iaa.PerspectiveTransform(scale=0.01, name="pt001", keep_size=True),
        iaa.PerspectiveTransform(scale=0.1, name="pt01", keep_size=True),
        iaa.PerspectiveTransform(scale=0.2, name="pt02", keep_size=True),
        iaa.PerspectiveTransform(scale=0.3, name="pt03", keep_size=True),
        iaa.PerspectiveTransform(scale=(0, 0.3), name="pt00to03", keep_size=True)
    ]

    print("original", image.shape)
    ia.imshow(kps[0].draw_on_image(image))

    print("-----------------")
    print("Random aug per image")
    print("-----------------")
    for aug in augs:
        images_aug = []
        for _ in range(16):
            aug_det = aug.to_deterministic()
            img_aug = aug_det.augment_image(image)
            kps_aug = aug_det.augment_keypoints(kps)[0]
            img_aug_kps = kps_aug.draw_on_image(img_aug)
            img_aug_kps = np.pad(img_aug_kps, ((1, 1), (1, 1), (0, 0)), mode="constant", constant_values=255)
            images_aug.append(img_aug_kps)
        print(aug.name)
        ia.imshow(ia.draw_grid(images_aug))

    print("----------------")
    print("6 channels")
    print("----------------")
    image6 = np.dstack([image, image])
    image6_aug = augs[1].augment_image(image6)
    ia.imshow(
        np.hstack([image6_aug[..., 0:3], image6_aug[..., 3:6]])
    ) 
开发者ID:aleju,项目名称:imgaug,代码行数:45,代码来源:check_perspective_transform.py

示例9: heavy_aug_on_fly

# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import PerspectiveTransform [as 别名]
def heavy_aug_on_fly(img, det_mask):
    """Do augmentation with different combination on each training batch
    """

    def image_heavy_augmentation(image, det_masks, ratio_operations=0.6):
        # according to the paper, operations such as shearing, fliping horizontal/vertical,
        # rotating, zooming and channel shifting will be apply
        sometimes = lambda aug: iaa.Sometimes(ratio_operations, aug)
        edge_detect_sometime = lambda aug: iaa.Sometimes(0.1, aug)
        elasitic_sometime = lambda aug:iaa.Sometimes(0.2, aug)
        add_gauss_noise = lambda aug: iaa.Sometimes(0.15, aug)
        hor_flip_angle = np.random.uniform(0, 1)
        ver_flip_angle = np.random.uniform(0, 1)
        seq = iaa.Sequential([
            iaa.SomeOf((0, 5), [
                iaa.Fliplr(hor_flip_angle),
                iaa.Flipud(ver_flip_angle),
                iaa.Affine(shear=(-16, 16)),
                iaa.Affine(scale={'x': (1, 1.6), 'y': (1, 1.6)}),
                iaa.PerspectiveTransform(scale=(0.01, 0.1)),

                # These are additional augmentation.
                #iaa.ContrastNormalization((0.75, 1.5))

            ]),

            edge_detect_sometime(iaa.OneOf([
                iaa.EdgeDetect(alpha=(0, 0.7)),
                iaa.DirectedEdgeDetect(alpha=(0,0.7), direction=(0.0, 1.0)
                                       )
            ])),
            add_gauss_noise(iaa.AdditiveGaussianNoise(loc=0,
                                                      scale=(0.0, 0.05*255),
                                                      per_channel=0.5)
                            ),
            iaa.Sometimes(0.3,
                          iaa.GaussianBlur(sigma=(0, 0.5))
                          ),
            elasitic_sometime(
                iaa.ElasticTransformation(alpha=(0.5, 3.5), sigma=0.25))
        ])

        seq_to_deterministic = seq.to_deterministic()
        aug_img = seq_to_deterministic.augment_images(image)
        aug_det_mask = seq_to_deterministic.augment_images(det_masks)
        return aug_img, aug_det_mask

    aug_image, aug_det_mask = image_heavy_augmentation(image=img, det_masks=det_mask)
    return aug_image, aug_det_mask 
开发者ID:zhuyiche,项目名称:sfcn-opi,代码行数:51,代码来源:util.py

示例10: main

# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import PerspectiveTransform [as 别名]
def main():
    image = ia.quokka(size=0.5)
    kps = [ia.KeypointsOnImage(
        [ia.Keypoint(x=245, y=203), ia.Keypoint(x=365, y=195), ia.Keypoint(x=313, y=269)],
        shape=(image.shape[0]*2, image.shape[1]*2)
    )]
    kps[0] = kps[0].on(image.shape)
    print("image shape:", image.shape)

    augs = [
        iaa.PerspectiveTransform(scale=0.01, name="pt001", keep_size=True),
        iaa.PerspectiveTransform(scale=0.1, name="pt01", keep_size=True),
        iaa.PerspectiveTransform(scale=0.2, name="pt02", keep_size=True),
        iaa.PerspectiveTransform(scale=0.3, name="pt03", keep_size=True),
        iaa.PerspectiveTransform(scale=(0, 0.3), name="pt00to03", keep_size=True)
    ]

    print("original", image.shape)
    misc.imshow(kps[0].draw_on_image(image))

    print("-----------------")
    print("Random aug per image")
    print("-----------------")
    for aug in augs:
        images_aug = []
        for _ in range(16):
            aug_det = aug.to_deterministic()
            img_aug = aug_det.augment_image(image)
            kps_aug = aug_det.augment_keypoints(kps)[0]
            img_aug_kps = kps_aug.draw_on_image(img_aug)
            img_aug_kps = np.pad(img_aug_kps, ((1, 1), (1, 1), (0, 0)), mode="constant", constant_values=255)
            #print(aug.name, img_aug_kps.shape, img_aug_kps.shape[1]/img_aug_kps.shape[0])
            images_aug.append(img_aug_kps)
            #misc.imshow(img_aug_kps)
        print(aug.name)
        misc.imshow(ia.draw_grid(images_aug))

    print("----------------")
    print("6 channels")
    print("----------------")
    image6 = np.dstack([image, image])
    image6_aug = augs[1].augment_image(image6)
    misc.imshow(
        np.hstack([image6_aug[..., 0:3], image6_aug[..., 3:6]])
    ) 
开发者ID:JoshuaPiinRueyPan,项目名称:ViolenceDetection,代码行数:47,代码来源:check_perspective_transform.py


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