augmenters.meta¶
Sequential¶
List augmenter that may contain other augmenters to apply in sequence or random order.
API link: Sequential
Example. Apply in predefined order:
import imgaug.augmenters as iaa
aug = iaa.Sequential([
iaa.Affine(translate_px={"x":-40}),
iaa.AdditiveGaussianNoise(scale=0.1*255)
])
Example. Apply in random order (note that the order is sampled once per batch and then the same for all images within the batch):
aug = iaa.Sequential([
iaa.Affine(translate_px={"x":-40}),
iaa.AdditiveGaussianNoise(scale=0.1*255)
], random_order=True)
SomeOf¶
List augmenter that applies only some of its children to images.
API link: SomeOf
Example. Apply two of four given augmenters:
import imgaug.augmenters as iaa
aug = iaa.SomeOf(2, [
iaa.Affine(rotate=45),
iaa.AdditiveGaussianNoise(scale=0.2*255),
iaa.Add(50, per_channel=True),
iaa.Sharpen(alpha=0.5)
])
Example.
Apply 0
to <max>
given augmenters (where <max>
is automatically
replaced with the number of children):
aug = iaa.SomeOf((0, None), [
iaa.Affine(rotate=45),
iaa.AdditiveGaussianNoise(scale=0.2*255),
iaa.Add(50, per_channel=True),
iaa.Sharpen(alpha=0.5)
])
Example. Pick two of four given augmenters and apply them in random order:
aug = iaa.SomeOf(2, [
iaa.Affine(rotate=45),
iaa.AdditiveGaussianNoise(scale=0.2*255),
iaa.Add(50, per_channel=True),
iaa.Sharpen(alpha=0.5)
], random_order=True)
OneOf¶
Augmenter that always executes exactly one of its children.
API link: OneOf()
Example. Apply one of four augmenters to each image:
import imgaug.augmenters as iaa
aug = iaa.OneOf([
iaa.Affine(rotate=45),
iaa.AdditiveGaussianNoise(scale=0.2*255),
iaa.Add(50, per_channel=True),
iaa.Sharpen(alpha=0.5)
])
Sometimes¶
Augment only p percent of all images with one or more augmenters.
API link: Sometimes
Example. Apply gaussian blur to about 50% of all images:
import imgaug.augmenters as iaa
aug = iaa.Sometimes(0.5, iaa.GaussianBlur(sigma=2.0))
Example. Apply gaussian blur to about 50% of all images. Apply a mixture of affine rotations and sharpening to the other 50%.
aug = iaa.Sometimes(
0.5,
iaa.GaussianBlur(sigma=2.0),
iaa.Sequential([iaa.Affine(rotate=45), iaa.Sharpen(alpha=1.0)])
)
WithChannels¶
Apply child augmenters to specific channels.
API link: WithChannels
Example.
Increase each pixel’s R-value (redness) by 10
to 100
:
import imgaug.augmenters as iaa
aug = iaa.WithChannels(0, iaa.Add((10, 100)))
Example.
Rotate each image’s red channel by 0
to 45
degrees:
aug = iaa.WithChannels(0, iaa.Affine(rotate=(0, 45)))
Noop¶
Augmenter that never changes input images (“no operation”).
API link: Noop
Example. Create an augmenter that does nothing:
import imgaug.augmenters as iaa
aug = iaa.Noop()
Lambda¶
Augmenter that calls a lambda function for each batch of input image.
API link: Lambda
Example. Replace in every image each fourth row with black pixels:
import imgaug.augmenters as iaa
def img_func(images, random_state, parents, hooks):
for img in images:
img[::4] = 0
return images
def keypoint_func(keypoints_on_images, random_state, parents, hooks):
return keypoints_on_images
aug = iaa.Lambda(img_func, keypoint_func)
AssertLambda¶
Augmenter that runs an assert on each batch of input images using a lambda function as condition.
API link: AssertLambda
TODO examples
AssertShape¶
Augmenter to make assumptions about the shape of input image(s) and keypoints.
API link: AssertShape
Example.
Check if each image in a batch has shape 32x32x3
, otherwise raise an
exception:
import imgaug.augmenters as iaa
seq = iaa.Sequential([
iaa.AssertShape((None, 32, 32, 3)),
iaa.Fliplr(0.5) # only executed if shape matches
])
Example.
Check if each image in a batch has a height in the range 32<=x<64
,
a width of exactly 64
and either 1
or 3
channels:
seq = iaa.Sequential([
iaa.AssertShape((None, (32, 64), 32, [1, 3])),
iaa.Fliplr(0.5)
])
ChannelShuffle¶
Randomize the order of channels in input images.
API link: ChannelShuffle
Example. Shuffle all channels of 35% of all images:
import imgaug.augmenters as iaa
aug = iaa.ChannelShuffle(0.35)
Example.
Shuffle only channels 0
and 1
of 35% of all images. As the new
channel orders 0, 1
and 1, 0
are both valid outcomes of the
shuffling, it means that for 0.35 * 0.5 = 0.175
or 17.5% of all images
the order of channels 0
and 1
is inverted.
aug = iaa.ChannelShuffle(0.35, channels=[0, 1])