欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

imgaug的使用(二)

程序员文章站 2024-03-19 22:18:40
...

1、关键点增强

官方示例

import imgaug as ia
import imgaug.augmenters as iaa
from imgaug.augmentables import Keypoint, KeypointsOnImage


ia.seed(1)

image = ia.quokka(size=(256, 256))
kps = KeypointsOnImage([
    Keypoint(x=65, y=100),
    Keypoint(x=75, y=200),
    Keypoint(x=100, y=100),
    Keypoint(x=200, y=80)
], shape=image.shape)

seq = iaa.Sequential([
    iaa.Multiply((1.2, 1.5)), # 在不影响keypoints的情况下,改变亮度
    iaa.Affine(
        rotate=10,
        scale=(0.5, 0.7)
    ) # 旋转10度,尺度变50-70%,这个操作影响keypoints
])

# 增强 keypoints and images.
image_aug, kps_aug = seq(image=image, keypoints=kps)

# 打印增强前后
# use after.x_int and after.y_int to get rounded integer coordinates
for i in range(len(kps.keypoints)):
    before = kps.keypoints[i]
    after = kps_aug.keypoints[i]
    print("Keypoint %d: (%.8f, %.8f) -> (%.8f, %.8f)" % (
        i, before.x, before.y, after.x, after.y)
    )

# 带有keypoints的增强前后的图像
image_before = kps.draw_on_image(image, size=7)
image_after = kps_aug.draw_on_image(image_aug, size=7)

imgaug的使用(二)