本文整理汇总了Python中imgaug.augmenters.ElasticTransformation方法的典型用法代码示例。如果您正苦于以下问题:Python augmenters.ElasticTransformation方法的具体用法?Python augmenters.ElasticTransformation怎么用?Python augmenters.ElasticTransformation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类imgaug.augmenters
的用法示例。
在下文中一共展示了augmenters.ElasticTransformation方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import ElasticTransformation [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))
示例2: __init__
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import ElasticTransformation [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)
示例3: chapter_augmenters_elastictransformation
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import ElasticTransformation [as 别名]
def chapter_augmenters_elastictransformation():
aug = iaa.ElasticTransformation(alpha=(0, 5.0), sigma=0.25)
run_and_save_augseq(
"elastictransformations.jpg", aug,
[ia.quokka(size=(128, 128)) for _ in range(8)], cols=4, rows=2,
quality=75
)
alphas = np.linspace(0.0, 5.0, num=8)
run_and_save_augseq(
"elastictransformations_vary_alpha.jpg",
[iaa.ElasticTransformation(alpha=alpha, sigma=0.25) for alpha in alphas],
[ia.quokka(size=(128, 128)) for _ in range(8)], cols=8, rows=1,
quality=75
)
sigmas = np.linspace(0.01, 1.0, num=8)
run_and_save_augseq(
"elastictransformations_vary_sigmas.jpg",
[iaa.ElasticTransformation(alpha=2.5, sigma=sigma) for sigma in sigmas],
[ia.quokka(size=(128, 128)) for _ in range(8)], cols=8, rows=1,
quality=75
)
###############################
# Parameters
###############################
示例4: _create_augment_pipeline
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import ElasticTransformation [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
示例5: build_augmentation_pipeline
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import ElasticTransformation [as 别名]
def build_augmentation_pipeline(self, height=None, width=None, apply_prob=0.5):
sometimes = lambda aug: iaa.Sometimes(apply_prob, aug)
pipeline = iaa.Sequential(random_order=False)
cfg = self.cfg
if cfg.get("fliplr", False):
opt = cfg.get("fliplr", False)
if type(opt) == int:
pipeline.add(sometimes(iaa.Fliplr(opt)))
else:
pipeline.add(sometimes(iaa.Fliplr(0.5)))
if cfg.get("rotation", False):
opt = cfg.get("rotation", False)
if type(opt) == int:
pipeline.add(sometimes(iaa.Affine(rotate=(-opt, opt))))
else:
pipeline.add(sometimes(iaa.Affine(rotate=(-10, 10))))
if cfg.get("hist_eq", False):
pipeline.add(sometimes(iaa.AllChannelsHistogramEqualization()))
if cfg.get("motion_blur", False):
opts = cfg.get("motion_blur", False)
if type(opts) == list:
opts = dict(opts)
pipeline.add(sometimes(iaa.MotionBlur(**opts)))
else:
pipeline.add(sometimes(iaa.MotionBlur(k=7, angle=(-90, 90))))
if cfg.get("covering", False):
pipeline.add(
sometimes(iaa.CoarseDropout((0, 0.02), size_percent=(0.01, 0.05)))
) # , per_channel=0.5)))
if cfg.get("elastic_transform", False):
pipeline.add(sometimes(iaa.ElasticTransformation(sigma=5)))
if cfg.get("gaussian_noise", False):
opt = cfg.get("gaussian_noise", False)
if type(opt) == int or type(opt) == float:
pipeline.add(
sometimes(
iaa.AdditiveGaussianNoise(
loc=0, scale=(0.0, opt), per_channel=0.5
)
)
)
else:
pipeline.add(
sometimes(
iaa.AdditiveGaussianNoise(
loc=0, scale=(0.0, 0.05 * 255), per_channel=0.5
)
)
)
if height is not None and width is not None:
pipeline.add(
iaa.Sometimes(
cfg.cropratio, iaa.CropAndPad(percent=(-0.3, 0.1), keep_size=False)
)
)
pipeline.add(iaa.Resize({"height": height, "width": width}))
return pipeline
示例6: heavy_aug_on_fly
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import ElasticTransformation [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
示例7: get_augmentations
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import ElasticTransformation [as 别名]
def get_augmentations():
# applies the given augmenter in 50% of all cases,
sometimes = lambda aug: iaa.Sometimes(0.5, aug)
# Define our sequence of augmentation steps that will be applied to every image
seq = iaa.Sequential([
# execute 0 to 5 of the following (less important) augmenters per image
iaa.SomeOf((0, 5),
[
iaa.OneOf([
iaa.GaussianBlur((0, 3.0)),
iaa.AverageBlur(k=(2, 7)),
iaa.MedianBlur(k=(3, 11)),
]),
iaa.Sharpen(alpha=(0, 1.0), lightness=(0.75, 1.5)),
iaa.Emboss(alpha=(0, 1.0), strength=(0, 2.0)),
# search either for all edges or for directed edges,
# blend the result with the original image using a blobby mask
iaa.SimplexNoiseAlpha(iaa.OneOf([
iaa.EdgeDetect(alpha=(0.5, 1.0)),
iaa.DirectedEdgeDetect(alpha=(0.5, 1.0), direction=(0.0, 1.0)),
])),
iaa.AdditiveGaussianNoise(loc=0, scale=(0.0, 0.05*255), per_channel=0.5),
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.Add((-10, 10), per_channel=0.5), # change brightness of images (by -10 to 10 of original value)
iaa.AddToHueAndSaturation((-20, 20)), # change hue and saturation
# either change the brightness of the whole image (sometimes
# per channel) or change the brightness of subareas
iaa.OneOf([
iaa.Multiply((0.5, 1.5), per_channel=0.5),
iaa.FrequencyNoiseAlpha(
exponent=(-4, 0),
first=iaa.Multiply((0.5, 1.5), per_channel=True),
second=iaa.ContrastNormalization((0.5, 2.0))
)
]),
iaa.ContrastNormalization((0.5, 2.0), per_channel=0.5), # improve or worsen the contrast
sometimes(iaa.ElasticTransformation(alpha=(0.5, 3.5), sigma=0.25)), # move pixels locally around (with random strengths)
],
random_order=True
)
],
random_order=True
)
return seq
### data transforms
示例8: main
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import ElasticTransformation [as 别名]
def main():
image = data.astronaut()
image = ia.imresize_single_image(image, (128, 128))
images = []
params = [
(0.25, 0.25),
(1.0, 0.25),
(2.0, 0.25),
(3.0, 0.25),
(0.25, 0.50),
(1.0, 0.50),
(2.0, 0.50),
(3.0, 0.50),
(0.25, 0.75),
(1.0, 0.75),
(2.0, 0.75),
(3.0, 0.75)
]
for (alpha, sigma) in params:
images_row = []
seqs_row = [
iaa.ElasticTransformation(alpha=alpha, sigma=sigma, mode="constant", cval=0, order=0),
iaa.ElasticTransformation(alpha=alpha, sigma=sigma, mode="constant", cval=128, order=0),
iaa.ElasticTransformation(alpha=alpha, sigma=sigma, mode="constant", cval=255, order=0),
iaa.ElasticTransformation(alpha=alpha, sigma=sigma, mode="constant", cval=0, order=1),
iaa.ElasticTransformation(alpha=alpha, sigma=sigma, mode="constant", cval=128, order=1),
iaa.ElasticTransformation(alpha=alpha, sigma=sigma, mode="constant", cval=255, order=1),
iaa.ElasticTransformation(alpha=alpha, sigma=sigma, mode="constant", cval=0, order=3),
iaa.ElasticTransformation(alpha=alpha, sigma=sigma, mode="constant", cval=128, order=3),
iaa.ElasticTransformation(alpha=alpha, sigma=sigma, mode="constant", cval=255, order=3),
iaa.ElasticTransformation(alpha=alpha, sigma=sigma, mode="nearest", order=0),
iaa.ElasticTransformation(alpha=alpha, sigma=sigma, mode="nearest", order=1),
iaa.ElasticTransformation(alpha=alpha, sigma=sigma, mode="nearest", order=2),
iaa.ElasticTransformation(alpha=alpha, sigma=sigma, mode="nearest", order=3),
iaa.ElasticTransformation(alpha=alpha, sigma=sigma, mode="reflect", order=0),
iaa.ElasticTransformation(alpha=alpha, sigma=sigma, mode="reflect", order=1),
iaa.ElasticTransformation(alpha=alpha, sigma=sigma, mode="reflect", order=2),
iaa.ElasticTransformation(alpha=alpha, sigma=sigma, mode="reflect", order=3),
iaa.ElasticTransformation(alpha=alpha, sigma=sigma, mode="wrap", order=0),
iaa.ElasticTransformation(alpha=alpha, sigma=sigma, mode="wrap", order=1),
iaa.ElasticTransformation(alpha=alpha, sigma=sigma, mode="wrap", order=2),
iaa.ElasticTransformation(alpha=alpha, sigma=sigma, mode="wrap", order=3)
]
for seq in seqs_row:
images_row.append(
seq.augment_image(image)
)
images.append(np.hstack(images_row))
misc.imshow(np.vstack(images))
misc.imsave("elastic_transformations.jpg", np.vstack(images))
示例9: example_heavy_augmentations
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import ElasticTransformation [as 别名]
def example_heavy_augmentations():
print("Example: Heavy Augmentations")
import imgaug as ia
from imgaug import augmenters as iaa
# random example images
images = np.random.randint(0, 255, (16, 128, 128, 3), dtype=np.uint8)
# Sometimes(0.5, ...) applies the given augmenter in 50% of all cases,
# e.g. Sometimes(0.5, GaussianBlur(0.3)) would blur roughly every second image.
st = 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_.
seq = iaa.Sequential([
iaa.Fliplr(0.5), # horizontally flip 50% of all images
iaa.Flipud(0.5), # vertically flip 50% of all images
st(iaa.Crop(percent=(0, 0.1))), # crop images by 0-10% of their height/width
st(iaa.GaussianBlur((0, 3.0))), # blur images with a sigma between 0 and 3.0
st(iaa.AdditiveGaussianNoise(loc=0, scale=(0.0, 0.05*255), per_channel=0.5)), # add gaussian noise to images
st(iaa.Dropout((0.0, 0.1), per_channel=0.5)), # randomly remove up to 10% of the pixels
st(iaa.Add((-10, 10), per_channel=0.5)), # change brightness of images (by -10 to 10 of original value)
st(iaa.Multiply((0.5, 1.5), per_channel=0.5)), # change brightness of images (50-150% of original value)
st(iaa.ContrastNormalization((0.5, 2.0), per_channel=0.5)), # improve or worsen the contrast
st(iaa.Grayscale((0.0, 1.0))), # blend with grayscale image
st(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_px={"x": (-16, 16), "y": (-16, 16)}, # translate by -16 to +16 pixels (per axis)
rotate=(-45, 45), # rotate by -45 to +45 degrees
shear=(-16, 16), # shear by -16 to +16 degrees
order=[0, 1], # use scikit-image's interpolation orders 0 (nearest neighbour) and 1 (bilinear)
cval=(0, 255), # if mode is constant, use a cval between 0 and 1.0
mode=ia.ALL # use any of scikit-image's warping modes (see 2nd image from the top for examples)
)),
st(iaa.ElasticTransformation(alpha=(0.5, 3.5), sigma=0.25)) # apply elastic transformations with random strengths
],
random_order=True # do all of the above in random order
)
images_aug = seq.augment_images(images)
# -----
# Make sure that the example really does something
assert not np.array_equal(images, images_aug)