本文整理汇总了Python中imgaug.augmenters.PiecewiseAffine方法的典型用法代码示例。如果您正苦于以下问题:Python augmenters.PiecewiseAffine方法的具体用法?Python augmenters.PiecewiseAffine怎么用?Python augmenters.PiecewiseAffine使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类imgaug.augmenters
的用法示例。
在下文中一共展示了augmenters.PiecewiseAffine方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import PiecewiseAffine [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)
示例2: init_augmentations
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import PiecewiseAffine [as 别名]
def init_augmentations(self):
if self.transform_probability > 0 and self.use_imgaug:
augmentations = iaa.Sometimes(
self.transform_probability,
iaa.Sequential([
iaa.SomeOf(
(1, None),
[
iaa.AddToHueAndSaturation(iap.Uniform(-20, 20), per_channel=True),
iaa.GaussianBlur(sigma=(0, 1.0)),
iaa.LinearContrast((0.75, 1.0)),
iaa.PiecewiseAffine(scale=(0.01, 0.02), mode='edge'),
],
random_order=True
),
iaa.Resize(
{"height": (16, self.image_size.height), "width": "keep-aspect-ratio"},
interpolation=imgaug.ALL
),
])
)
else:
augmentations = None
return augmentations
示例3: amaugimg
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import PiecewiseAffine [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
示例4: main
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import PiecewiseAffine [as 别名]
def main():
image = ia.data.quokka(size=0.5)
print(image.shape)
kps = [
ia.KeypointsOnImage(
[
ia.Keypoint(x=123, y=102),
ia.Keypoint(x=182, y=98),
ia.Keypoint(x=155, y=134),
ia.Keypoint(x=-20, y=20)
],
shape=(image.shape[0], image.shape[1])
)
]
print("image shape:", image.shape)
augs = [
iaa.PiecewiseAffine(scale=0.05),
iaa.PiecewiseAffine(scale=0.1),
iaa.PiecewiseAffine(scale=0.2)
]
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 = keypoints_draw_on_image(kps_aug, 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))
# TODO why was this used here?
示例5: __init__
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import PiecewiseAffine [as 别名]
def __init__(self, image_ids, epoch_size):
super().__init__()
self.image_ids = image_ids
self.epoch_size = epoch_size
self.elastic = iaa.ElasticTransformation(alpha=(0.25, 1.2), sigma=0.2)
#self.piecewiseAffine = iaa.PiecewiseAffine(scale=(0.01, 0.05))
示例6: __init__
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import PiecewiseAffine [as 别名]
def __init__(self, scale=(0.03, 0.05), nb_rows=4, nb_cols=4, prob=.5):
super().__init__(prob)
self.processor = iaa.PiecewiseAffine(scale, nb_rows, nb_cols)
示例7: imgaug
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import PiecewiseAffine [as 别名]
def imgaug(args):
# Number of batches and batch size for this example
filename, root, fold_A = args
img = cv2.imread(os.path.join(root,filename))
print('image opened ' + os.path.join(root,filename))
batch_size = 4
for i in range(0,batch_size):
imageio.imwrite(os.path.join(root, os.path.splitext(filename)[0] + '_' + str(i) + '.jpg'), img) #convert the current image in B into a jpg from png
nb_batches = 1
# Example augmentation sequence to run in the background
sometimes = lambda aug: iaa.Sometimes(0.4, aug)
augseq = iaa.Sequential(
[
iaa.PiecewiseAffine(scale=(0.01, 0.01005))
]
)
# Make batches out of the example image (here: 10 batches, each 32 times
# the example image)
batches = []
for _ in range(nb_batches):
batches.append(Batch(images=[img] * batch_size))
#Save images
for batch in augseq.augment_batches(batches, background=False):
count = 0
for img in batch.images_aug:
path = os.path.join(fold_A,root.rsplit('/', 1)[-1], os.path.splitext(filename)[0] + '_' + str(count) + '.jpg')
cv2.imwrite(path, img)
print('image saved as: ' + path)
count +=1
示例8: chapter_augmenters_piecewiseaffine
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import PiecewiseAffine [as 别名]
def chapter_augmenters_piecewiseaffine():
aug = iaa.PiecewiseAffine(scale=(0.01, 0.05))
run_and_save_augseq(
"piecewiseaffine.jpg", aug,
[ia.quokka(size=(128, 128)) for _ in range(8)], cols=4, rows=2,
quality=75
)
aug = iaa.PiecewiseAffine(scale=(0.01, 0.05))
run_and_save_augseq(
"piecewiseaffine_checkerboard.jpg", aug,
[checkerboard(size=(128, 128)) for _ in range(8)], cols=4, rows=2,
quality=75
)
scales = np.linspace(0.0, 0.3, num=8)
run_and_save_augseq(
"piecewiseaffine_vary_scales.jpg",
[iaa.PiecewiseAffine(scale=scale) for scale in scales],
[checkerboard(size=(128, 128)) for _ in range(8)], cols=8, rows=1,
quality=75
)
gridvals = [2, 4, 6, 8, 10, 12, 14, 16]
run_and_save_augseq(
"piecewiseaffine_vary_grid.jpg",
[iaa.PiecewiseAffine(scale=0.05, nb_rows=g, nb_cols=g) for g in gridvals],
[checkerboard(size=(128, 128)) for _ in range(8)], cols=8, rows=1,
quality=75
)
示例9: processor
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import PiecewiseAffine [as 别名]
def processor(self):
return iaa.PiecewiseAffine(self.scale, self.nb_rows, self.nb_cols, self.order, self.cval, self.mode)
示例10: _create_augment_pipeline
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import PiecewiseAffine [as 别名]
def _create_augment_pipeline():
from imgaug import augmenters as iaa
### augmentors by https://github.com/aleju/imgaug
sometimes = lambda aug: iaa.Sometimes(0.5, aug)
# Define our sequence of augmentation steps that will be applied to every image
# All augmenters with per_channel=0.5 will sample one value _per image_
# in 50% of all cases. In all other cases they will sample new values
# _per channel_.
aug_pipe = iaa.Sequential(
[
# apply the following augmenters to most images
#iaa.Fliplr(0.5), # horizontally flip 50% of all images
#iaa.Flipud(0.2), # vertically flip 20% of all images
#sometimes(iaa.Crop(percent=(0, 0.1))), # crop images by 0-10% of their height/width
sometimes(iaa.Affine(
#scale={"x": (0.8, 1.2), "y": (0.8, 1.2)}, # scale images to 80-120% of their size, individually per axis
#translate_percent={"x": (-0.2, 0.2), "y": (-0.2, 0.2)}, # translate by -20 to +20 percent (per axis)
#rotate=(-5, 5), # rotate by -45 to +45 degrees
#shear=(-5, 5), # shear by -16 to +16 degrees
#order=[0, 1], # use nearest neighbour or bilinear interpolation (fast)
#cval=(0, 255), # if mode is constant, use a cval between 0 and 255
#mode=ia.ALL # use any of scikit-image's warping modes (see 2nd image from the top for examples)
)),
# execute 0 to 5 of the following (less important) augmenters per image
# don't execute all of them, as that would often be way too strong
iaa.SomeOf((0, 5),
[
#sometimes(iaa.Superpixels(p_replace=(0, 1.0), n_segments=(20, 200))), # convert images into their superpixel representation
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.Sharpen(alpha=(0, 1.0), lightness=(0.75, 1.5)), # sharpen images
#iaa.Emboss(alpha=(0, 1.0), strength=(0, 2.0)), # emboss images
# search either for all edges or for directed edges
#sometimes(iaa.OneOf([
# iaa.EdgeDetect(alpha=(0, 0.7)),
# iaa.DirectedEdgeDetect(alpha=(0, 0.7), direction=(0.0, 1.0)),
#])),
iaa.AdditiveGaussianNoise(loc=0, scale=(0.0, 0.05*255), per_channel=0.5), # add gaussian noise to images
iaa.OneOf([
iaa.Dropout((0.01, 0.1), per_channel=0.5), # randomly remove up to 10% of the pixels
#iaa.CoarseDropout((0.03, 0.15), size_percent=(0.02, 0.05), per_channel=0.2),
]),
#iaa.Invert(0.05, per_channel=True), # invert color channels
iaa.Add((-10, 10), per_channel=0.5), # change brightness of images (by -10 to 10 of original value)
iaa.Multiply((0.5, 1.5), per_channel=0.5), # change brightness of images (50-150% of original value)
iaa.ContrastNormalization((0.5, 2.0), per_channel=0.5), # improve or worsen the contrast
#iaa.Grayscale(alpha=(0.0, 1.0)),
#sometimes(iaa.ElasticTransformation(alpha=(0.5, 3.5), sigma=0.25)), # move pixels locally around (with random strengths)
#sometimes(iaa.PiecewiseAffine(scale=(0.01, 0.05))) # sometimes move parts of the image around
],
random_order=True
)
],
random_order=True
)
return aug_pipe
示例11: main
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import PiecewiseAffine [as 别名]
def main():
image = ia.quokka(size=0.5)
print(image.shape)
kps = [
ia.KeypointsOnImage(
[
ia.Keypoint(x=123, y=102),
ia.Keypoint(x=182, y=98),
ia.Keypoint(x=155, y=134),
#ia.Keypoint(x=255, y=213),
#ia.Keypoint(x=375, y=205),
#ia.Keypoint(x=323, y=279),
#ia.Keypoint(x=265, y=223),
#ia.Keypoint(x=385, y=215),
#ia.Keypoint(x=333, y=289),
#ia.Keypoint(x=275, y=233),
#ia.Keypoint(x=395, y=225),
#ia.Keypoint(x=343, y=299),
ia.Keypoint(x=-20, y=20)
],
shape=(image.shape[0], image.shape[1])
)
]
#kps[0] = kps[0].on(image.shape)
print("image shape:", image.shape)
augs = [
#iaa.PiecewiseAffine(scale=0),
iaa.PiecewiseAffine(scale=0.05),
iaa.PiecewiseAffine(scale=0.1),
iaa.PiecewiseAffine(scale=0.2)
]
#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 = keypoints_draw_on_image(kps_aug, 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))