imgaug.augmenters.color

Augmenters that affect image colors or image colorspaces.

List of augmenters:

class imgaug.augmenters.color.AddToBrightness(add=(-30, 30), to_colorspace=['YCrCb', 'HSV', 'HLS', 'Lab', 'Luv', 'YUV'], from_colorspace='RGB', seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.color.MultiplyAndAddToBrightness

Add to the brightness channels of input images.

This is a wrapper around WithBrightnessChannels and hence performs internally the same projection to random colorspaces.

Added in 0.4.0.

Supported dtypes:

See MultiplyAndAddToBrightness.

Parameters:
  • add (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – See Add.
  • to_colorspace (imgaug.ALL or str or list of str or imgaug.parameters.StochasticParameter, optional) – See WithBrightnessChannels.
  • from_colorspace (str, optional) – See WithBrightnessChannels.
  • seed (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – See __init__().
  • name (None or str, optional) – See __init__().
  • random_state (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – Old name for parameter seed. Its usage will not yet cause a deprecation warning, but it is still recommended to use seed now. Outdated since 0.4.0.
  • deterministic (bool, optional) – Deprecated since 0.4.0. See method to_deterministic() for an alternative and for details about what the “deterministic mode” actually does.

Examples

>>> import imgaug.augmenters as iaa
>>> aug = iaa.AddToBrightness((-30, 30))

Convert each image to a colorspace with a brightness-related channel, extract that channel, add between -30 and 30 and convert back to the original colorspace.

Methods

__call__(self, *args, **kwargs) Alias for augment().
augment(self[, return_batch, hooks]) Augment a batch.
augment_batch(self, batch[, hooks]) Deprecated.
augment_batch_(self, batch[, parents, hooks]) Augment a single batch in-place.
augment_batches(self, batches[, hooks, …]) Augment multiple batches.
augment_bounding_boxes(self, …[, parents, …]) Augment a batch of bounding boxes.
augment_heatmaps(self, heatmaps[, parents, …]) Augment a batch of heatmaps.
augment_image(self, image[, hooks]) Augment a single image.
augment_images(self, images[, parents, hooks]) Augment a batch of images.
augment_keypoints(self, keypoints_on_images) Augment a batch of keypoints/landmarks.
augment_line_strings(self, …[, parents, hooks]) Augment a batch of line strings.
augment_polygons(self, polygons_on_images[, …]) Augment a batch of polygons.
augment_segmentation_maps(self, segmaps[, …]) Augment a batch of segmentation maps.
copy(self) Create a shallow copy of this Augmenter instance.
copy_random_state(self, source[, recursive, …]) Copy the RNGs from a source augmenter sequence.
copy_random_state_(self, source[, …]) Copy the RNGs from a source augmenter sequence (in-place).
deepcopy(self) Create a deep copy of this Augmenter instance.
draw_grid(self, images, rows, cols) Augment images and draw the results as a single grid-like image.
find_augmenters(self, func[, parents, flat]) Find augmenters that match a condition.
find_augmenters_by_name(self, name[, regex, …]) Find augmenter(s) by name.
find_augmenters_by_names(self, names[, …]) Find augmenter(s) by names.
get_all_children(self[, flat]) Get all children of this augmenter as a list.
get_children_lists(self) See get_children_lists().
get_parameters(self) See get_parameters().
localize_random_state(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
localize_random_state_(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
pool(self[, processes, maxtasksperchild, seed]) Create a pool used for multicore augmentation.
remove_augmenters(self, func[, copy, …]) Remove this augmenter or children that match a condition.
remove_augmenters_(self, func[, parents]) Remove in-place children of this augmenter that match a condition.
remove_augmenters_inplace(self, func[, parents]) Deprecated.
reseed(self[, random_state, deterministic_too]) Deprecated.
seed_(self[, entropy, deterministic_too]) Seed this augmenter and all of its children.
show_grid(self, images, rows, cols) Augment images and plot the results as a single grid-like image.
to_deterministic(self[, n]) Convert this augmenter from a stochastic to a deterministic one.
class imgaug.augmenters.color.AddToHue(value=(-255, 255), from_colorspace='RGB', seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.color.AddToHueAndSaturation

Add random values to the hue of images.

The augmenter first transforms images to HSV colorspace, then adds random values to the H channel and afterwards converts back to RGB.

If you want to change both the hue and the saturation, it is recommended to use AddToHueAndSaturation as otherwise the image will be converted twice to HSV and back to RGB.

This augmenter is a shortcut for AddToHueAndSaturation(value_hue=...).

Supported dtypes:

See AddToHueAndSaturation.

Parameters:
  • value (None or int or tuple of int or list of int or imgaug.parameters.StochasticParameter, optional) – Value to add to the hue of all pixels. This is expected to be in the range -255 to +255 and will automatically be projected to an angular representation using (hue/255) * (360/2) (OpenCV’s hue representation is in the range [0, 180] instead of [0, 360]).

    • If an integer, then that value will be used for all images.
    • If a tuple (a, b), then a value from the discrete range [a, b] will be sampled per image.
    • If a list, then a random value will be sampled from that list per image.
    • If a StochasticParameter, then a value will be sampled from that parameter per image.
  • from_colorspace (str, optional) – See change_colorspace_().

  • seed (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – See __init__().

  • name (None or str, optional) – See __init__().

  • random_state (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – Old name for parameter seed. Its usage will not yet cause a deprecation warning, but it is still recommended to use seed now. Outdated since 0.4.0.

  • deterministic (bool, optional) – Deprecated since 0.4.0. See method to_deterministic() for an alternative and for details about what the “deterministic mode” actually does.

Examples

>>> import imgaug.augmenters as iaa
>>> aug = iaa.AddToHue((-50, 50))

Sample random values from the discrete uniform range [-50..50], convert them to angular representation and add them to the hue, i.e. to the H channel in HSV colorspace.

Methods

__call__(self, *args, **kwargs) Alias for augment().
augment(self[, return_batch, hooks]) Augment a batch.
augment_batch(self, batch[, hooks]) Deprecated.
augment_batch_(self, batch[, parents, hooks]) Augment a single batch in-place.
augment_batches(self, batches[, hooks, …]) Augment multiple batches.
augment_bounding_boxes(self, …[, parents, …]) Augment a batch of bounding boxes.
augment_heatmaps(self, heatmaps[, parents, …]) Augment a batch of heatmaps.
augment_image(self, image[, hooks]) Augment a single image.
augment_images(self, images[, parents, hooks]) Augment a batch of images.
augment_keypoints(self, keypoints_on_images) Augment a batch of keypoints/landmarks.
augment_line_strings(self, …[, parents, hooks]) Augment a batch of line strings.
augment_polygons(self, polygons_on_images[, …]) Augment a batch of polygons.
augment_segmentation_maps(self, segmaps[, …]) Augment a batch of segmentation maps.
copy(self) Create a shallow copy of this Augmenter instance.
copy_random_state(self, source[, recursive, …]) Copy the RNGs from a source augmenter sequence.
copy_random_state_(self, source[, …]) Copy the RNGs from a source augmenter sequence (in-place).
deepcopy(self) Create a deep copy of this Augmenter instance.
draw_grid(self, images, rows, cols) Augment images and draw the results as a single grid-like image.
find_augmenters(self, func[, parents, flat]) Find augmenters that match a condition.
find_augmenters_by_name(self, name[, regex, …]) Find augmenter(s) by name.
find_augmenters_by_names(self, names[, …]) Find augmenter(s) by names.
get_all_children(self[, flat]) Get all children of this augmenter as a list.
get_children_lists(self) Get a list of lists of children of this augmenter.
get_parameters(self) See get_parameters().
localize_random_state(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
localize_random_state_(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
pool(self[, processes, maxtasksperchild, seed]) Create a pool used for multicore augmentation.
remove_augmenters(self, func[, copy, …]) Remove this augmenter or children that match a condition.
remove_augmenters_(self, func[, parents]) Remove in-place children of this augmenter that match a condition.
remove_augmenters_inplace(self, func[, parents]) Deprecated.
reseed(self[, random_state, deterministic_too]) Deprecated.
seed_(self[, entropy, deterministic_too]) Seed this augmenter and all of its children.
show_grid(self, images, rows, cols) Augment images and plot the results as a single grid-like image.
to_deterministic(self[, n]) Convert this augmenter from a stochastic to a deterministic one.
class imgaug.augmenters.color.AddToHueAndSaturation(value=None, value_hue=None, value_saturation=None, per_channel=False, from_colorspace='RGB', seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.meta.Augmenter

Increases or decreases hue and saturation by random values.

The augmenter first transforms images to HSV colorspace, then adds random values to the H and S channels and afterwards converts back to RGB.

This augmenter is faster than using WithHueAndSaturation in combination with Add.

TODO add float support

Supported dtypes:

See change_colorspace_().

Parameters:
  • value (None or int or tuple of int or list of int or imgaug.parameters.StochasticParameter, optional) – Value to add to the hue and saturation of all pixels. It is expected to be in the range -255 to +255.

    • If this is None, value_hue and/or value_saturation may be set to values other than None.
    • If an integer, then that value will be used for all images.
    • If a tuple (a, b), then a value from the discrete range [a, b] will be sampled per image.
    • If a list, then a random value will be sampled from that list per image.
    • If a StochasticParameter, then a value will be sampled from that parameter per image.
  • value_hue (None or int or tuple of int or list of int or imgaug.parameters.StochasticParameter, optional) – Value to add to the hue of all pixels. This is expected to be in the range -255 to +255 and will automatically be projected to an angular representation using (hue/255) * (360/2) (OpenCV’s hue representation is in the range [0, 180] instead of [0, 360]). Only this or value may be set, not both.

    • If this and value_saturation are both None, value may be set to a non-None value.
    • If an integer, then that value will be used for all images.
    • If a tuple (a, b), then a value from the discrete range [a, b] will be sampled per image.
    • If a list, then a random value will be sampled from that list per image.
    • If a StochasticParameter, then a value will be sampled from that parameter per image.
  • value_saturation (None or int or tuple of int or list of int or imgaug.parameters.StochasticParameter, optional) – Value to add to the saturation of all pixels. It is expected to be in the range -255 to +255. Only this or value may be set, not both.

    • If this and value_hue are both None, value may be set to a non-None value.
    • If an integer, then that value will be used for all images.
    • If a tuple (a, b), then a value from the discrete range [a, b] will be sampled per image.
    • If a list, then a random value will be sampled from that list per image.
    • If a StochasticParameter, then a value will be sampled from that parameter per image.
  • per_channel (bool or float, optional) – Whether to sample per image only one value from value and use it for both hue and saturation (False) or to sample independently one value for hue and one for saturation (True). If this value is a float p, then for p percent of all images per_channel will be treated as True, otherwise as False.

    This parameter has no effect is value_hue and/or value_saturation are used instead of value.

  • from_colorspace (str, optional) – See change_colorspace_().

  • seed (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – See __init__().

  • name (None or str, optional) – See __init__().

  • random_state (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – Old name for parameter seed. Its usage will not yet cause a deprecation warning, but it is still recommended to use seed now. Outdated since 0.4.0.

  • deterministic (bool, optional) – Deprecated since 0.4.0. See method to_deterministic() for an alternative and for details about what the “deterministic mode” actually does.

Examples

>>> import imgaug.augmenters as iaa
>>> aug = iaa.AddToHueAndSaturation((-50, 50), per_channel=True)

Add random values between -50 and 50 to the hue and saturation (independently per channel and the same value for all pixels within that channel).

Methods

__call__(self, *args, **kwargs) Alias for augment().
augment(self[, return_batch, hooks]) Augment a batch.
augment_batch(self, batch[, hooks]) Deprecated.
augment_batch_(self, batch[, parents, hooks]) Augment a single batch in-place.
augment_batches(self, batches[, hooks, …]) Augment multiple batches.
augment_bounding_boxes(self, …[, parents, …]) Augment a batch of bounding boxes.
augment_heatmaps(self, heatmaps[, parents, …]) Augment a batch of heatmaps.
augment_image(self, image[, hooks]) Augment a single image.
augment_images(self, images[, parents, hooks]) Augment a batch of images.
augment_keypoints(self, keypoints_on_images) Augment a batch of keypoints/landmarks.
augment_line_strings(self, …[, parents, hooks]) Augment a batch of line strings.
augment_polygons(self, polygons_on_images[, …]) Augment a batch of polygons.
augment_segmentation_maps(self, segmaps[, …]) Augment a batch of segmentation maps.
copy(self) Create a shallow copy of this Augmenter instance.
copy_random_state(self, source[, recursive, …]) Copy the RNGs from a source augmenter sequence.
copy_random_state_(self, source[, …]) Copy the RNGs from a source augmenter sequence (in-place).
deepcopy(self) Create a deep copy of this Augmenter instance.
draw_grid(self, images, rows, cols) Augment images and draw the results as a single grid-like image.
find_augmenters(self, func[, parents, flat]) Find augmenters that match a condition.
find_augmenters_by_name(self, name[, regex, …]) Find augmenter(s) by name.
find_augmenters_by_names(self, names[, …]) Find augmenter(s) by names.
get_all_children(self[, flat]) Get all children of this augmenter as a list.
get_children_lists(self) Get a list of lists of children of this augmenter.
get_parameters(self) See get_parameters().
localize_random_state(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
localize_random_state_(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
pool(self[, processes, maxtasksperchild, seed]) Create a pool used for multicore augmentation.
remove_augmenters(self, func[, copy, …]) Remove this augmenter or children that match a condition.
remove_augmenters_(self, func[, parents]) Remove in-place children of this augmenter that match a condition.
remove_augmenters_inplace(self, func[, parents]) Deprecated.
reseed(self[, random_state, deterministic_too]) Deprecated.
seed_(self[, entropy, deterministic_too]) Seed this augmenter and all of its children.
show_grid(self, images, rows, cols) Augment images and plot the results as a single grid-like image.
to_deterministic(self[, n]) Convert this augmenter from a stochastic to a deterministic one.
get_parameters(self)[source]

See get_parameters().

class imgaug.augmenters.color.AddToSaturation(value=(-75, 75), from_colorspace='RGB', seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.color.AddToHueAndSaturation

Add random values to the saturation of images.

The augmenter first transforms images to HSV colorspace, then adds random values to the S channel and afterwards converts back to RGB.

If you want to change both the hue and the saturation, it is recommended to use AddToHueAndSaturation as otherwise the image will be converted twice to HSV and back to RGB.

This augmenter is a shortcut for AddToHueAndSaturation(value_saturation=...).

Supported dtypes:

See AddToHueAndSaturation.

Parameters:
  • value (None or int or tuple of int or list of int or imgaug.parameters.StochasticParameter, optional) – Value to add to the saturation of all pixels. It is expected to be in the range -255 to +255.

    • If an integer, then that value will be used for all images.
    • If a tuple (a, b), then a value from the discrete range [a, b] will be sampled per image.
    • If a list, then a random value will be sampled from that list per image.
    • If a StochasticParameter, then a value will be sampled from that parameter per image.
  • from_colorspace (str, optional) – See change_colorspace_().

  • seed (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – See __init__().

  • name (None or str, optional) – See __init__().

  • random_state (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – Old name for parameter seed. Its usage will not yet cause a deprecation warning, but it is still recommended to use seed now. Outdated since 0.4.0.

  • deterministic (bool, optional) – Deprecated since 0.4.0. See method to_deterministic() for an alternative and for details about what the “deterministic mode” actually does.

Examples

>>> import imgaug.augmenters as iaa
>>> aug = iaa.AddToSaturation((-50, 50))

Sample random values from the discrete uniform range [-50..50], and add them to the saturation, i.e. to the S channel in HSV colorspace.

Methods

__call__(self, *args, **kwargs) Alias for augment().
augment(self[, return_batch, hooks]) Augment a batch.
augment_batch(self, batch[, hooks]) Deprecated.
augment_batch_(self, batch[, parents, hooks]) Augment a single batch in-place.
augment_batches(self, batches[, hooks, …]) Augment multiple batches.
augment_bounding_boxes(self, …[, parents, …]) Augment a batch of bounding boxes.
augment_heatmaps(self, heatmaps[, parents, …]) Augment a batch of heatmaps.
augment_image(self, image[, hooks]) Augment a single image.
augment_images(self, images[, parents, hooks]) Augment a batch of images.
augment_keypoints(self, keypoints_on_images) Augment a batch of keypoints/landmarks.
augment_line_strings(self, …[, parents, hooks]) Augment a batch of line strings.
augment_polygons(self, polygons_on_images[, …]) Augment a batch of polygons.
augment_segmentation_maps(self, segmaps[, …]) Augment a batch of segmentation maps.
copy(self) Create a shallow copy of this Augmenter instance.
copy_random_state(self, source[, recursive, …]) Copy the RNGs from a source augmenter sequence.
copy_random_state_(self, source[, …]) Copy the RNGs from a source augmenter sequence (in-place).
deepcopy(self) Create a deep copy of this Augmenter instance.
draw_grid(self, images, rows, cols) Augment images and draw the results as a single grid-like image.
find_augmenters(self, func[, parents, flat]) Find augmenters that match a condition.
find_augmenters_by_name(self, name[, regex, …]) Find augmenter(s) by name.
find_augmenters_by_names(self, names[, …]) Find augmenter(s) by names.
get_all_children(self[, flat]) Get all children of this augmenter as a list.
get_children_lists(self) Get a list of lists of children of this augmenter.
get_parameters(self) See get_parameters().
localize_random_state(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
localize_random_state_(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
pool(self[, processes, maxtasksperchild, seed]) Create a pool used for multicore augmentation.
remove_augmenters(self, func[, copy, …]) Remove this augmenter or children that match a condition.
remove_augmenters_(self, func[, parents]) Remove in-place children of this augmenter that match a condition.
remove_augmenters_inplace(self, func[, parents]) Deprecated.
reseed(self[, random_state, deterministic_too]) Deprecated.
seed_(self[, entropy, deterministic_too]) Seed this augmenter and all of its children.
show_grid(self, images, rows, cols) Augment images and plot the results as a single grid-like image.
to_deterministic(self[, n]) Convert this augmenter from a stochastic to a deterministic one.
class imgaug.augmenters.color.ChangeColorTemperature(kelvin=(1000, 11000), from_colorspace='RGB', seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.meta.Augmenter

Change the temperature to a provided Kelvin value.

Low Kelvin values around 1000 to 4000 will result in red, yellow or orange images. Kelvin values around 10000 to 40000 will result in progressively darker blue tones.

Color temperatures taken from http://www.vendian.org/mncharity/dir3/blackbody/UnstableURLs/bbr_color.html

Basic method to change color temperatures taken from https://stackoverflow.com/a/11888449

Added in 0.4.0.

Supported dtypes:

See change_color_temperatures_().

Parameters:

kelvin (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – Temperature in Kelvin. The temperatures of images will be modified to this value. Must be in the interval [1000, 40000].

  • If a number, exactly that value will always be used.
  • If a tuple (a, b), then a value from the interval [a, b] will be sampled per image.
  • If a list, then a random value will be sampled from that

list per image. * If a StochasticParameter, then a value will be sampled per

image from that parameter.

Examples

>>> import imgaug.augmenters as iaa
>>> aug = iaa.ChangeColorTemperature((1100, 10000))

Create an augmenter that changes the color temperature of images to a random value between 1100 and 10000 Kelvin.

Methods

__call__(self, *args, **kwargs) Alias for augment().
augment(self[, return_batch, hooks]) Augment a batch.
augment_batch(self, batch[, hooks]) Deprecated.
augment_batch_(self, batch[, parents, hooks]) Augment a single batch in-place.
augment_batches(self, batches[, hooks, …]) Augment multiple batches.
augment_bounding_boxes(self, …[, parents, …]) Augment a batch of bounding boxes.
augment_heatmaps(self, heatmaps[, parents, …]) Augment a batch of heatmaps.
augment_image(self, image[, hooks]) Augment a single image.
augment_images(self, images[, parents, hooks]) Augment a batch of images.
augment_keypoints(self, keypoints_on_images) Augment a batch of keypoints/landmarks.
augment_line_strings(self, …[, parents, hooks]) Augment a batch of line strings.
augment_polygons(self, polygons_on_images[, …]) Augment a batch of polygons.
augment_segmentation_maps(self, segmaps[, …]) Augment a batch of segmentation maps.
copy(self) Create a shallow copy of this Augmenter instance.
copy_random_state(self, source[, recursive, …]) Copy the RNGs from a source augmenter sequence.
copy_random_state_(self, source[, …]) Copy the RNGs from a source augmenter sequence (in-place).
deepcopy(self) Create a deep copy of this Augmenter instance.
draw_grid(self, images, rows, cols) Augment images and draw the results as a single grid-like image.
find_augmenters(self, func[, parents, flat]) Find augmenters that match a condition.
find_augmenters_by_name(self, name[, regex, …]) Find augmenter(s) by name.
find_augmenters_by_names(self, names[, …]) Find augmenter(s) by names.
get_all_children(self[, flat]) Get all children of this augmenter as a list.
get_children_lists(self) Get a list of lists of children of this augmenter.
get_parameters(self) See get_parameters().
localize_random_state(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
localize_random_state_(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
pool(self[, processes, maxtasksperchild, seed]) Create a pool used for multicore augmentation.
remove_augmenters(self, func[, copy, …]) Remove this augmenter or children that match a condition.
remove_augmenters_(self, func[, parents]) Remove in-place children of this augmenter that match a condition.
remove_augmenters_inplace(self, func[, parents]) Deprecated.
reseed(self[, random_state, deterministic_too]) Deprecated.
seed_(self[, entropy, deterministic_too]) Seed this augmenter and all of its children.
show_grid(self, images, rows, cols) Augment images and plot the results as a single grid-like image.
to_deterministic(self[, n]) Convert this augmenter from a stochastic to a deterministic one.
get_parameters(self)[source]

See get_parameters().

class imgaug.augmenters.color.ChangeColorspace(to_colorspace, from_colorspace='RGB', alpha=1.0, seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.meta.Augmenter

Augmenter to change the colorspace of images.

Note

This augmenter is not tested. Some colorspaces might work, others might not.

..note:

This augmenter tries to project the colorspace value range on
0-255. It outputs dtype=uint8 images.

Supported dtypes:

See change_colorspace_().

Parameters:
  • to_colorspace (str or list of str or imgaug.parameters.StochasticParameter) – The target colorspace. Allowed strings are: RGB, BGR, GRAY, CIE, YCrCb, HSV, HLS, Lab, Luv. These are also accessible via imgaug.augmenters.color.CSPACE_<NAME>, e.g. imgaug.augmenters.CSPACE_YCrCb.

    • If a string, it must be among the allowed colorspaces.
    • If a list, it is expected to be a list of strings, each one being an allowed colorspace. A random element from the list will be chosen per image.
    • If a StochasticParameter, it is expected to return string. A new sample will be drawn per image.
  • from_colorspace (str, optional) – The source colorspace (of the input images). See to_colorspace. Only a single string is allowed.

  • alpha (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – The alpha value of the new colorspace when overlayed over the old one. A value close to 1.0 means that mostly the new colorspace is visible. A value close to 0.0 means, that mostly the old image is visible.

    • If an int or float, exactly that value will be used.
    • If a tuple (a, b), a random value from the range a <= x <= b will be sampled per image.
    • If a list, then a random value will be sampled from that list per image.
    • If a StochasticParameter, a value will be sampled from the parameter per image.
  • seed (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – See __init__().

  • name (None or str, optional) – See __init__().

  • random_state (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – Old name for parameter seed. Its usage will not yet cause a deprecation warning, but it is still recommended to use seed now. Outdated since 0.4.0.

  • deterministic (bool, optional) – Deprecated since 0.4.0. See method to_deterministic() for an alternative and for details about what the “deterministic mode” actually does.

Methods

__call__(self, *args, **kwargs) Alias for augment().
augment(self[, return_batch, hooks]) Augment a batch.
augment_batch(self, batch[, hooks]) Deprecated.
augment_batch_(self, batch[, parents, hooks]) Augment a single batch in-place.
augment_batches(self, batches[, hooks, …]) Augment multiple batches.
augment_bounding_boxes(self, …[, parents, …]) Augment a batch of bounding boxes.
augment_heatmaps(self, heatmaps[, parents, …]) Augment a batch of heatmaps.
augment_image(self, image[, hooks]) Augment a single image.
augment_images(self, images[, parents, hooks]) Augment a batch of images.
augment_keypoints(self, keypoints_on_images) Augment a batch of keypoints/landmarks.
augment_line_strings(self, …[, parents, hooks]) Augment a batch of line strings.
augment_polygons(self, polygons_on_images[, …]) Augment a batch of polygons.
augment_segmentation_maps(self, segmaps[, …]) Augment a batch of segmentation maps.
copy(self) Create a shallow copy of this Augmenter instance.
copy_random_state(self, source[, recursive, …]) Copy the RNGs from a source augmenter sequence.
copy_random_state_(self, source[, …]) Copy the RNGs from a source augmenter sequence (in-place).
deepcopy(self) Create a deep copy of this Augmenter instance.
draw_grid(self, images, rows, cols) Augment images and draw the results as a single grid-like image.
find_augmenters(self, func[, parents, flat]) Find augmenters that match a condition.
find_augmenters_by_name(self, name[, regex, …]) Find augmenter(s) by name.
find_augmenters_by_names(self, names[, …]) Find augmenter(s) by names.
get_all_children(self[, flat]) Get all children of this augmenter as a list.
get_children_lists(self) Get a list of lists of children of this augmenter.
get_parameters(self) See get_parameters().
localize_random_state(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
localize_random_state_(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
pool(self[, processes, maxtasksperchild, seed]) Create a pool used for multicore augmentation.
remove_augmenters(self, func[, copy, …]) Remove this augmenter or children that match a condition.
remove_augmenters_(self, func[, parents]) Remove in-place children of this augmenter that match a condition.
remove_augmenters_inplace(self, func[, parents]) Deprecated.
reseed(self[, random_state, deterministic_too]) Deprecated.
seed_(self[, entropy, deterministic_too]) Seed this augmenter and all of its children.
show_grid(self, images, rows, cols) Augment images and plot the results as a single grid-like image.
to_deterministic(self[, n]) Convert this augmenter from a stochastic to a deterministic one.
BGR = 'BGR'
CIE = 'CIE'
COLORSPACES = {'BGR', 'CIE', 'GRAY', 'HLS', 'HSV', 'Lab', 'Luv', 'RGB', 'YCrCb'}
CV_VARS = {'BGR2CIE': <MagicMock id='140303154096728'>, 'BGR2GRAY': <MagicMock id='140303154088312'>, 'BGR2HLS': <MagicMock id='140303153990904'>, 'BGR2HSV': <MagicMock id='140303154129944'>, 'BGR2Lab': <MagicMock id='140303154175448'>, 'BGR2Luv': <MagicMock id='140303154179768'>, 'BGR2RGB': <MagicMock id='140303154092184'>, 'BGR2YCrCb': <MagicMock id='140303154113336'>, 'HLS2BGR': <MagicMock id='140303154246264'>, 'HLS2RGB': <MagicMock id='140303154221464'>, 'HSV2BGR': <MagicMock id='140303154229432'>, 'HSV2RGB': <MagicMock id='140303154196376'>, 'Lab2BGR': <MagicMock id='140303154275608'>, 'Lab2RGB': <MagicMock id='140303154295864'>, 'RGB2BGR': <MagicMock id='140303153942936'>, 'RGB2CIE': <MagicMock id='140303153992536'>, 'RGB2GRAY': <MagicMock id='140303153971832'>, 'RGB2HLS': <MagicMock id='140303154017784'>, 'RGB2HSV': <MagicMock id='140303153997080'>, 'RGB2Lab': <MagicMock id='140303154038488'>, 'RGB2Luv': <MagicMock id='140303154046904'>, 'RGB2YCrCb': <MagicMock id='140303154005048'>}
GRAY = 'GRAY'
HLS = 'HLS'
HSV = 'HSV'
Lab = 'Lab'
Luv = 'Luv'
RGB = 'RGB'
YCrCb = 'YCrCb'
get_parameters(self)[source]

See get_parameters().

class imgaug.augmenters.color.Grayscale(alpha=1, from_colorspace='RGB', seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.color.ChangeColorspace

Augmenter to convert images to their grayscale versions.

Note

Number of output channels is still 3, i.e. this augmenter just “removes” color.

TODO check dtype support

Supported dtypes:

See change_colorspace_().

Parameters:
  • alpha (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – The alpha value of the grayscale image when overlayed over the old image. A value close to 1.0 means, that mostly the new grayscale image is visible. A value close to 0.0 means, that mostly the old image is visible.

    • If a number, exactly that value will always be used.
    • If a tuple (a, b), a random value from the range a <= x <= b will be sampled per image.
    • If a list, then a random value will be sampled from that list per image.
    • If a StochasticParameter, a value will be sampled from the parameter per image.
  • from_colorspace (str, optional) – The source colorspace (of the input images). See change_colorspace_().

  • seed (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – See __init__().

  • name (None or str, optional) – See __init__().

  • random_state (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – Old name for parameter seed. Its usage will not yet cause a deprecation warning, but it is still recommended to use seed now. Outdated since 0.4.0.

  • deterministic (bool, optional) – Deprecated since 0.4.0. See method to_deterministic() for an alternative and for details about what the “deterministic mode” actually does.

Examples

>>> import imgaug.augmenters as iaa
>>> aug = iaa.Grayscale(alpha=1.0)

Creates an augmenter that turns images to their grayscale versions.

>>> import imgaug.augmenters as iaa
>>> aug = iaa.Grayscale(alpha=(0.0, 1.0))

Creates an augmenter that turns images to their grayscale versions with an alpha value in the range 0 <= alpha <= 1. An alpha value of 0.5 would mean, that the output image is 50 percent of the input image and 50 percent of the grayscale image (i.e. 50 percent of color removed).

Methods

__call__(self, *args, **kwargs) Alias for augment().
augment(self[, return_batch, hooks]) Augment a batch.
augment_batch(self, batch[, hooks]) Deprecated.
augment_batch_(self, batch[, parents, hooks]) Augment a single batch in-place.
augment_batches(self, batches[, hooks, …]) Augment multiple batches.
augment_bounding_boxes(self, …[, parents, …]) Augment a batch of bounding boxes.
augment_heatmaps(self, heatmaps[, parents, …]) Augment a batch of heatmaps.
augment_image(self, image[, hooks]) Augment a single image.
augment_images(self, images[, parents, hooks]) Augment a batch of images.
augment_keypoints(self, keypoints_on_images) Augment a batch of keypoints/landmarks.
augment_line_strings(self, …[, parents, hooks]) Augment a batch of line strings.
augment_polygons(self, polygons_on_images[, …]) Augment a batch of polygons.
augment_segmentation_maps(self, segmaps[, …]) Augment a batch of segmentation maps.
copy(self) Create a shallow copy of this Augmenter instance.
copy_random_state(self, source[, recursive, …]) Copy the RNGs from a source augmenter sequence.
copy_random_state_(self, source[, …]) Copy the RNGs from a source augmenter sequence (in-place).
deepcopy(self) Create a deep copy of this Augmenter instance.
draw_grid(self, images, rows, cols) Augment images and draw the results as a single grid-like image.
find_augmenters(self, func[, parents, flat]) Find augmenters that match a condition.
find_augmenters_by_name(self, name[, regex, …]) Find augmenter(s) by name.
find_augmenters_by_names(self, names[, …]) Find augmenter(s) by names.
get_all_children(self[, flat]) Get all children of this augmenter as a list.
get_children_lists(self) Get a list of lists of children of this augmenter.
get_parameters(self) See get_parameters().
localize_random_state(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
localize_random_state_(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
pool(self[, processes, maxtasksperchild, seed]) Create a pool used for multicore augmentation.
remove_augmenters(self, func[, copy, …]) Remove this augmenter or children that match a condition.
remove_augmenters_(self, func[, parents]) Remove in-place children of this augmenter that match a condition.
remove_augmenters_inplace(self, func[, parents]) Deprecated.
reseed(self[, random_state, deterministic_too]) Deprecated.
seed_(self[, entropy, deterministic_too]) Seed this augmenter and all of its children.
show_grid(self, images, rows, cols) Augment images and plot the results as a single grid-like image.
to_deterministic(self[, n]) Convert this augmenter from a stochastic to a deterministic one.
imgaug.augmenters.color.InColorspace(to_colorspace, from_colorspace='RGB', children=None, seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Deprecated. Use WithColorspace instead.

Convert images to another colorspace.

class imgaug.augmenters.color.KMeansColorQuantization(n_colors=(2, 16), from_colorspace='RGB', to_colorspace=['RGB', 'Lab'], max_size=128, interpolation='linear', seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.color._AbstractColorQuantization

Quantize colors using k-Means clustering.

This “collects” the colors from the input image, groups them into k clusters using k-Means clustering and replaces the colors in the input image using the cluster centroids.

This is slower than UniformColorQuantization, but adapts dynamically to the color range in the input image.

Note

This augmenter expects input images to be either grayscale or to have 3 or 4 channels and use colorspace from_colorspace. If images have 4 channels, it is assumed that the 4th channel is an alpha channel and it will not be quantized.

Supported dtypes:

if (image size <= max_size):

if (image size > max_size):

Parameters:
  • n_colors (int or tuple of int or list of int or imgaug.parameters.StochasticParameter, optional) – Target number of colors in the generated output image. This corresponds to the number of clusters in k-Means, i.e. k. Sampled values below 2 will always be clipped to 2.

    • If a number, exactly that value will always be used.
    • If a tuple (a, b), then a value from the discrete interval [a..b] will be sampled per image.
    • If a list, then a random value will be sampled from that list per image.
    • If a StochasticParameter, then a value will be sampled per image from that parameter.
  • to_colorspace (None or str or list of str or imgaug.parameters.StochasticParameter) – The colorspace in which to perform the quantization. See change_colorspace_() for valid values. This will be ignored for grayscale input images.

    • If None the colorspace of input images will not be changed.
    • If a string, it must be among the allowed colorspaces.
    • If a list, it is expected to be a list of strings, each one being an allowed colorspace. A random element from the list will be chosen per image.
    • If a StochasticParameter, it is expected to return string. A new sample will be drawn per image.
  • from_colorspace (str, optional) – The colorspace of the input images. See to_colorspace. Only a single string is allowed.

  • max_size (int or None, optional) – Maximum image size at which to perform the augmentation. If the width or height of an image exceeds this value, it will be downscaled before running the augmentation so that the longest side matches max_size. This is done to speed up the augmentation. The final output image has the same size as the input image. Use None to apply no downscaling.

  • interpolation (int or str, optional) – Interpolation method to use during downscaling when max_size is exceeded. Valid methods are the same as in imresize_single_image().

  • seed (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – See __init__().

  • name (None or str, optional) – See __init__().

  • random_state (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – Old name for parameter seed. Its usage will not yet cause a deprecation warning, but it is still recommended to use seed now. Outdated since 0.4.0.

  • deterministic (bool, optional) – Deprecated since 0.4.0. See method to_deterministic() for an alternative and for details about what the “deterministic mode” actually does.

Examples

>>> import imgaug.augmenters as iaa
>>> aug = iaa.KMeansColorQuantization()

Create an augmenter to apply k-Means color quantization to images using a random amount of colors, sampled uniformly from the interval [2..16]. It assumes the input image colorspace to be RGB and clusters colors randomly in RGB or Lab colorspace.

>>> aug = iaa.KMeansColorQuantization(n_colors=8)

Create an augmenter that quantizes images to (up to) eight colors.

>>> aug = iaa.KMeansColorQuantization(n_colors=(4, 16))

Create an augmenter that quantizes images to (up to) n colors, where n is randomly and uniformly sampled from the discrete interval [4..16].

>>> aug = iaa.KMeansColorQuantization(
>>>     from_colorspace=iaa.CSPACE_BGR)

Create an augmenter that quantizes input images that are in BGR colorspace. The quantization happens in RGB or Lab colorspace, into which the images are temporarily converted.

>>> aug = iaa.KMeansColorQuantization(
>>>     to_colorspace=[iaa.CSPACE_RGB, iaa.CSPACE_HSV])

Create an augmenter that quantizes images by clustering colors randomly in either RGB or HSV colorspace. The assumed input colorspace of images is RGB.

Attributes:
n_colors

Alias for property counts.

Methods

__call__(self, *args, **kwargs) Alias for augment().
augment(self[, return_batch, hooks]) Augment a batch.
augment_batch(self, batch[, hooks]) Deprecated.
augment_batch_(self, batch[, parents, hooks]) Augment a single batch in-place.
augment_batches(self, batches[, hooks, …]) Augment multiple batches.
augment_bounding_boxes(self, …[, parents, …]) Augment a batch of bounding boxes.
augment_heatmaps(self, heatmaps[, parents, …]) Augment a batch of heatmaps.
augment_image(self, image[, hooks]) Augment a single image.
augment_images(self, images[, parents, hooks]) Augment a batch of images.
augment_keypoints(self, keypoints_on_images) Augment a batch of keypoints/landmarks.
augment_line_strings(self, …[, parents, hooks]) Augment a batch of line strings.
augment_polygons(self, polygons_on_images[, …]) Augment a batch of polygons.
augment_segmentation_maps(self, segmaps[, …]) Augment a batch of segmentation maps.
copy(self) Create a shallow copy of this Augmenter instance.
copy_random_state(self, source[, recursive, …]) Copy the RNGs from a source augmenter sequence.
copy_random_state_(self, source[, …]) Copy the RNGs from a source augmenter sequence (in-place).
deepcopy(self) Create a deep copy of this Augmenter instance.
draw_grid(self, images, rows, cols) Augment images and draw the results as a single grid-like image.
find_augmenters(self, func[, parents, flat]) Find augmenters that match a condition.
find_augmenters_by_name(self, name[, regex, …]) Find augmenter(s) by name.
find_augmenters_by_names(self, names[, …]) Find augmenter(s) by names.
get_all_children(self[, flat]) Get all children of this augmenter as a list.
get_children_lists(self) Get a list of lists of children of this augmenter.
get_parameters(self) See get_parameters().
localize_random_state(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
localize_random_state_(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
pool(self[, processes, maxtasksperchild, seed]) Create a pool used for multicore augmentation.
remove_augmenters(self, func[, copy, …]) Remove this augmenter or children that match a condition.
remove_augmenters_(self, func[, parents]) Remove in-place children of this augmenter that match a condition.
remove_augmenters_inplace(self, func[, parents]) Deprecated.
reseed(self[, random_state, deterministic_too]) Deprecated.
seed_(self[, entropy, deterministic_too]) Seed this augmenter and all of its children.
show_grid(self, images, rows, cols) Augment images and plot the results as a single grid-like image.
to_deterministic(self[, n]) Convert this augmenter from a stochastic to a deterministic one.
n_colors

Alias for property counts.

Added in 0.4.0.

class imgaug.augmenters.color.MultiplyAndAddToBrightness(mul=(0.7, 1.3), add=(-30, 30), to_colorspace=['YCrCb', 'HSV', 'HLS', 'Lab', 'Luv', 'YUV'], from_colorspace='RGB', random_order=True, seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.color.WithBrightnessChannels

Multiply and add to the brightness channels of input images.

This is a wrapper around WithBrightnessChannels and hence performs internally the same projection to random colorspaces.

Added in 0.4.0.

Supported dtypes:

See WithBrightnessChannels.

Parameters:
  • mul (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – See Multiply.
  • add (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – See Add.
  • to_colorspace (imgaug.ALL or str or list of str or imgaug.parameters.StochasticParameter, optional) – See WithBrightnessChannels.
  • from_colorspace (str, optional) – See WithBrightnessChannels.
  • random_order (bool, optional) – Whether to apply the add and multiply operations in random order (True). If False, this augmenter will always first multiply and then add.
  • seed (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – See __init__().
  • name (None or str, optional) – See __init__().
  • random_state (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – Old name for parameter seed. Its usage will not yet cause a deprecation warning, but it is still recommended to use seed now. Outdated since 0.4.0.
  • deterministic (bool, optional) – Deprecated since 0.4.0. See method to_deterministic() for an alternative and for details about what the “deterministic mode” actually does.

Examples

>>> import imgaug.augmenters as iaa
>>> aug = iaa.MultiplyAndAddToBrightness(mul=(0.5, 1.5), add=(-30, 30))

Convert each image to a colorspace with a brightness-related channel, extract that channel, multiply it by a factor between 0.5 and 1.5, add a value between -30 and 30 and convert back to the original colorspace.

Methods

__call__(self, *args, **kwargs) Alias for augment().
augment(self[, return_batch, hooks]) Augment a batch.
augment_batch(self, batch[, hooks]) Deprecated.
augment_batch_(self, batch[, parents, hooks]) Augment a single batch in-place.
augment_batches(self, batches[, hooks, …]) Augment multiple batches.
augment_bounding_boxes(self, …[, parents, …]) Augment a batch of bounding boxes.
augment_heatmaps(self, heatmaps[, parents, …]) Augment a batch of heatmaps.
augment_image(self, image[, hooks]) Augment a single image.
augment_images(self, images[, parents, hooks]) Augment a batch of images.
augment_keypoints(self, keypoints_on_images) Augment a batch of keypoints/landmarks.
augment_line_strings(self, …[, parents, hooks]) Augment a batch of line strings.
augment_polygons(self, polygons_on_images[, …]) Augment a batch of polygons.
augment_segmentation_maps(self, segmaps[, …]) Augment a batch of segmentation maps.
copy(self) Create a shallow copy of this Augmenter instance.
copy_random_state(self, source[, recursive, …]) Copy the RNGs from a source augmenter sequence.
copy_random_state_(self, source[, …]) Copy the RNGs from a source augmenter sequence (in-place).
deepcopy(self) Create a deep copy of this Augmenter instance.
draw_grid(self, images, rows, cols) Augment images and draw the results as a single grid-like image.
find_augmenters(self, func[, parents, flat]) Find augmenters that match a condition.
find_augmenters_by_name(self, name[, regex, …]) Find augmenter(s) by name.
find_augmenters_by_names(self, names[, …]) Find augmenter(s) by names.
get_all_children(self[, flat]) Get all children of this augmenter as a list.
get_children_lists(self) See get_children_lists().
get_parameters(self) See get_parameters().
localize_random_state(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
localize_random_state_(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
pool(self[, processes, maxtasksperchild, seed]) Create a pool used for multicore augmentation.
remove_augmenters(self, func[, copy, …]) Remove this augmenter or children that match a condition.
remove_augmenters_(self, func[, parents]) Remove in-place children of this augmenter that match a condition.
remove_augmenters_inplace(self, func[, parents]) Deprecated.
reseed(self[, random_state, deterministic_too]) Deprecated.
seed_(self[, entropy, deterministic_too]) Seed this augmenter and all of its children.
show_grid(self, images, rows, cols) Augment images and plot the results as a single grid-like image.
to_deterministic(self[, n]) Convert this augmenter from a stochastic to a deterministic one.
class imgaug.augmenters.color.MultiplyBrightness(mul=(0.7, 1.3), to_colorspace=['YCrCb', 'HSV', 'HLS', 'Lab', 'Luv', 'YUV'], from_colorspace='RGB', seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.color.MultiplyAndAddToBrightness

Multiply the brightness channels of input images.

This is a wrapper around WithBrightnessChannels and hence performs internally the same projection to random colorspaces.

Added in 0.4.0.

Supported dtypes:

See MultiplyAndAddToBrightness.

Parameters:
  • mul (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – See Multiply.
  • to_colorspace (imgaug.ALL or str or list of str or imgaug.parameters.StochasticParameter, optional) – See WithBrightnessChannels.
  • from_colorspace (str, optional) – See WithBrightnessChannels.
  • seed (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – See __init__().
  • name (None or str, optional) – See __init__().
  • random_state (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – Old name for parameter seed. Its usage will not yet cause a deprecation warning, but it is still recommended to use seed now. Outdated since 0.4.0.
  • deterministic (bool, optional) – Deprecated since 0.4.0. See method to_deterministic() for an alternative and for details about what the “deterministic mode” actually does.

Examples

>>> import imgaug.augmenters as iaa
>>> aug = iaa.MultiplyBrightness((0.5, 1.5))

Convert each image to a colorspace with a brightness-related channel, extract that channel, multiply it by a factor between 0.5 and 1.5, and convert back to the original colorspace.

Methods

__call__(self, *args, **kwargs) Alias for augment().
augment(self[, return_batch, hooks]) Augment a batch.
augment_batch(self, batch[, hooks]) Deprecated.
augment_batch_(self, batch[, parents, hooks]) Augment a single batch in-place.
augment_batches(self, batches[, hooks, …]) Augment multiple batches.
augment_bounding_boxes(self, …[, parents, …]) Augment a batch of bounding boxes.
augment_heatmaps(self, heatmaps[, parents, …]) Augment a batch of heatmaps.
augment_image(self, image[, hooks]) Augment a single image.
augment_images(self, images[, parents, hooks]) Augment a batch of images.
augment_keypoints(self, keypoints_on_images) Augment a batch of keypoints/landmarks.
augment_line_strings(self, …[, parents, hooks]) Augment a batch of line strings.
augment_polygons(self, polygons_on_images[, …]) Augment a batch of polygons.
augment_segmentation_maps(self, segmaps[, …]) Augment a batch of segmentation maps.
copy(self) Create a shallow copy of this Augmenter instance.
copy_random_state(self, source[, recursive, …]) Copy the RNGs from a source augmenter sequence.
copy_random_state_(self, source[, …]) Copy the RNGs from a source augmenter sequence (in-place).
deepcopy(self) Create a deep copy of this Augmenter instance.
draw_grid(self, images, rows, cols) Augment images and draw the results as a single grid-like image.
find_augmenters(self, func[, parents, flat]) Find augmenters that match a condition.
find_augmenters_by_name(self, name[, regex, …]) Find augmenter(s) by name.
find_augmenters_by_names(self, names[, …]) Find augmenter(s) by names.
get_all_children(self[, flat]) Get all children of this augmenter as a list.
get_children_lists(self) See get_children_lists().
get_parameters(self) See get_parameters().
localize_random_state(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
localize_random_state_(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
pool(self[, processes, maxtasksperchild, seed]) Create a pool used for multicore augmentation.
remove_augmenters(self, func[, copy, …]) Remove this augmenter or children that match a condition.
remove_augmenters_(self, func[, parents]) Remove in-place children of this augmenter that match a condition.
remove_augmenters_inplace(self, func[, parents]) Deprecated.
reseed(self[, random_state, deterministic_too]) Deprecated.
seed_(self[, entropy, deterministic_too]) Seed this augmenter and all of its children.
show_grid(self, images, rows, cols) Augment images and plot the results as a single grid-like image.
to_deterministic(self[, n]) Convert this augmenter from a stochastic to a deterministic one.
class imgaug.augmenters.color.MultiplyHue(mul=(-3.0, 3.0), from_colorspace='RGB', seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.color.MultiplyHueAndSaturation

Multiply the hue of images by random values.

The augmenter first transforms images to HSV colorspace, then multiplies the pixel values in the H channel and afterwards converts back to RGB.

This augmenter is a shortcut for MultiplyHueAndSaturation(mul_hue=...).

Supported dtypes:

See MultiplyHueAndSaturation.

Parameters:
  • mul (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – Multiplier with which to multiply all hue values. This is expected to be in the range -10.0 to +10.0 and will automatically be projected to an angular representation using (hue/255) * (360/2) (OpenCV’s hue representation is in the range [0, 180] instead of [0, 360]). Only this or mul may be set, not both.

    • If a number, then that multiplier will be used for all images.
    • If a tuple (a, b), then a value from the continuous range [a, b] will be sampled per image.
    • If a list, then a random value will be sampled from that list per image.
    • If a StochasticParameter, then a value will be sampled from that parameter per image.
  • from_colorspace (str, optional) – See change_colorspace_().

  • seed (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – See __init__().

  • name (None or str, optional) – See __init__().

  • random_state (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – Old name for parameter seed. Its usage will not yet cause a deprecation warning, but it is still recommended to use seed now. Outdated since 0.4.0.

  • deterministic (bool, optional) – Deprecated since 0.4.0. See method to_deterministic() for an alternative and for details about what the “deterministic mode” actually does.

Examples

>>> import imgaug.augmenters as iaa
>>> aug = iaa.MultiplyHue((0.5, 1.5))

Multiply the hue channel of images using random values between 0.5 and 1.5.

Methods

__call__(self, *args, **kwargs) Alias for augment().
augment(self[, return_batch, hooks]) Augment a batch.
augment_batch(self, batch[, hooks]) Deprecated.
augment_batch_(self, batch[, parents, hooks]) Augment a single batch in-place.
augment_batches(self, batches[, hooks, …]) Augment multiple batches.
augment_bounding_boxes(self, …[, parents, …]) Augment a batch of bounding boxes.
augment_heatmaps(self, heatmaps[, parents, …]) Augment a batch of heatmaps.
augment_image(self, image[, hooks]) Augment a single image.
augment_images(self, images[, parents, hooks]) Augment a batch of images.
augment_keypoints(self, keypoints_on_images) Augment a batch of keypoints/landmarks.
augment_line_strings(self, …[, parents, hooks]) Augment a batch of line strings.
augment_polygons(self, polygons_on_images[, …]) Augment a batch of polygons.
augment_segmentation_maps(self, segmaps[, …]) Augment a batch of segmentation maps.
copy(self) Create a shallow copy of this Augmenter instance.
copy_random_state(self, source[, recursive, …]) Copy the RNGs from a source augmenter sequence.
copy_random_state_(self, source[, …]) Copy the RNGs from a source augmenter sequence (in-place).
deepcopy(self) Create a deep copy of this Augmenter instance.
draw_grid(self, images, rows, cols) Augment images and draw the results as a single grid-like image.
find_augmenters(self, func[, parents, flat]) Find augmenters that match a condition.
find_augmenters_by_name(self, name[, regex, …]) Find augmenter(s) by name.
find_augmenters_by_names(self, names[, …]) Find augmenter(s) by names.
get_all_children(self[, flat]) Get all children of this augmenter as a list.
get_children_lists(self) See get_children_lists().
get_parameters(self) See get_parameters().
localize_random_state(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
localize_random_state_(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
pool(self[, processes, maxtasksperchild, seed]) Create a pool used for multicore augmentation.
remove_augmenters(self, func[, copy, …]) Remove this augmenter or children that match a condition.
remove_augmenters_(self, func[, parents]) Remove in-place children of this augmenter that match a condition.
remove_augmenters_inplace(self, func[, parents]) Deprecated.
reseed(self[, random_state, deterministic_too]) Deprecated.
seed_(self[, entropy, deterministic_too]) Seed this augmenter and all of its children.
show_grid(self, images, rows, cols) Augment images and plot the results as a single grid-like image.
to_deterministic(self[, n]) Convert this augmenter from a stochastic to a deterministic one.
class imgaug.augmenters.color.MultiplyHueAndSaturation(mul=None, mul_hue=None, mul_saturation=None, per_channel=False, from_colorspace='RGB', seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.color.WithHueAndSaturation

Multipy hue and saturation by random values.

The augmenter first transforms images to HSV colorspace, then multiplies the pixel values in the H and S channels and afterwards converts back to RGB.

This augmenter is a wrapper around WithHueAndSaturation.

Supported dtypes:

See WithHueAndSaturation.

Parameters:
  • mul (None or number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – Multiplier with which to multiply all hue and saturation values of all pixels. It is expected to be in the range -10.0 to +10.0. Note that values of 0.0 or lower will remove all saturation.

    • If this is None, mul_hue and/or mul_saturation may be set to values other than None.
    • If a number, then that multiplier will be used for all images.
    • If a tuple (a, b), then a value from the continuous range [a, b] will be sampled per image.
    • If a list, then a random value will be sampled from that list per image.
    • If a StochasticParameter, then a value will be sampled from that parameter per image.
  • mul_hue (None or number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – Multiplier with which to multiply all hue values. This is expected to be in the range -10.0 to +10.0 and will automatically be projected to an angular representation using (hue/255) * (360/2) (OpenCV’s hue representation is in the range [0, 180] instead of [0, 360]). Only this or mul may be set, not both.

    • If this and mul_saturation are both None, mul may be set to a non-None value.
    • If a number, then that multiplier will be used for all images.
    • If a tuple (a, b), then a value from the continuous range [a, b] will be sampled per image.
    • If a list, then a random value will be sampled from that list per image.
    • If a StochasticParameter, then a value will be sampled from that parameter per image.
  • mul_saturation (None or number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – Multiplier with which to multiply all saturation values. It is expected to be in the range 0.0 to +10.0. Only this or mul may be set, not both.

    • If this and mul_hue are both None, mul may be set to a non-None value.
    • If a number, then that value will be used for all images.
    • If a tuple (a, b), then a value from the continuous range [a, b] will be sampled per image.
    • If a list, then a random value will be sampled from that list per image.
    • If a StochasticParameter, then a value will be sampled from that parameter per image.
  • per_channel (bool or float, optional) – Whether to sample per image only one value from mul and use it for both hue and saturation (False) or to sample independently one value for hue and one for saturation (True). If this value is a float p, then for p percent of all images per_channel will be treated as True, otherwise as False.

    This parameter has no effect if mul_hue and/or mul_saturation are used instead of mul.

  • from_colorspace (str, optional) – See change_colorspace_().

  • seed (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – See __init__().

  • name (None or str, optional) – See __init__().

  • random_state (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – Old name for parameter seed. Its usage will not yet cause a deprecation warning, but it is still recommended to use seed now. Outdated since 0.4.0.

  • deterministic (bool, optional) – Deprecated since 0.4.0. See method to_deterministic() for an alternative and for details about what the “deterministic mode” actually does.

Examples

>>> import imgaug.augmenters as iaa
>>> aug = iaa.MultiplyHueAndSaturation((0.5, 1.5), per_channel=True)

Multiply hue and saturation by random values between 0.5 and 1.5 (independently per channel and the same value for all pixels within that channel). The hue will be automatically projected to an angular representation.

>>> import imgaug.augmenters as iaa
>>> aug = iaa.MultiplyHueAndSaturation(mul_hue=(0.5, 1.5))

Multiply only the hue by random values between 0.5 and 1.5.

>>> import imgaug.augmenters as iaa
>>> aug = iaa.MultiplyHueAndSaturation(mul_saturation=(0.5, 1.5))

Multiply only the saturation by random values between 0.5 and 1.5.

Methods

__call__(self, *args, **kwargs) Alias for augment().
augment(self[, return_batch, hooks]) Augment a batch.
augment_batch(self, batch[, hooks]) Deprecated.
augment_batch_(self, batch[, parents, hooks]) Augment a single batch in-place.
augment_batches(self, batches[, hooks, …]) Augment multiple batches.
augment_bounding_boxes(self, …[, parents, …]) Augment a batch of bounding boxes.
augment_heatmaps(self, heatmaps[, parents, …]) Augment a batch of heatmaps.
augment_image(self, image[, hooks]) Augment a single image.
augment_images(self, images[, parents, hooks]) Augment a batch of images.
augment_keypoints(self, keypoints_on_images) Augment a batch of keypoints/landmarks.
augment_line_strings(self, …[, parents, hooks]) Augment a batch of line strings.
augment_polygons(self, polygons_on_images[, …]) Augment a batch of polygons.
augment_segmentation_maps(self, segmaps[, …]) Augment a batch of segmentation maps.
copy(self) Create a shallow copy of this Augmenter instance.
copy_random_state(self, source[, recursive, …]) Copy the RNGs from a source augmenter sequence.
copy_random_state_(self, source[, …]) Copy the RNGs from a source augmenter sequence (in-place).
deepcopy(self) Create a deep copy of this Augmenter instance.
draw_grid(self, images, rows, cols) Augment images and draw the results as a single grid-like image.
find_augmenters(self, func[, parents, flat]) Find augmenters that match a condition.
find_augmenters_by_name(self, name[, regex, …]) Find augmenter(s) by name.
find_augmenters_by_names(self, names[, …]) Find augmenter(s) by names.
get_all_children(self[, flat]) Get all children of this augmenter as a list.
get_children_lists(self) See get_children_lists().
get_parameters(self) See get_parameters().
localize_random_state(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
localize_random_state_(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
pool(self[, processes, maxtasksperchild, seed]) Create a pool used for multicore augmentation.
remove_augmenters(self, func[, copy, …]) Remove this augmenter or children that match a condition.
remove_augmenters_(self, func[, parents]) Remove in-place children of this augmenter that match a condition.
remove_augmenters_inplace(self, func[, parents]) Deprecated.
reseed(self[, random_state, deterministic_too]) Deprecated.
seed_(self[, entropy, deterministic_too]) Seed this augmenter and all of its children.
show_grid(self, images, rows, cols) Augment images and plot the results as a single grid-like image.
to_deterministic(self[, n]) Convert this augmenter from a stochastic to a deterministic one.
class imgaug.augmenters.color.MultiplySaturation(mul=(0.0, 3.0), from_colorspace='RGB', seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.color.MultiplyHueAndSaturation

Multiply the saturation of images by random values.

The augmenter first transforms images to HSV colorspace, then multiplies the pixel values in the H channel and afterwards converts back to RGB.

This augmenter is a shortcut for MultiplyHueAndSaturation(mul_saturation=...).

Supported dtypes:

See MultiplyHueAndSaturation.

Parameters:
  • mul (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – Multiplier with which to multiply all saturation values. It is expected to be in the range 0.0 to +10.0.

    • If a number, then that value will be used for all images.
    • If a tuple (a, b), then a value from the continuous range [a, b] will be sampled per image.
    • If a list, then a random value will be sampled from that list per image.
    • If a StochasticParameter, then a value will be sampled from that parameter per image.
  • from_colorspace (str, optional) – See change_colorspace_().

  • seed (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – See __init__().

  • name (None or str, optional) – See __init__().

  • random_state (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – Old name for parameter seed. Its usage will not yet cause a deprecation warning, but it is still recommended to use seed now. Outdated since 0.4.0.

  • deterministic (bool, optional) – Deprecated since 0.4.0. See method to_deterministic() for an alternative and for details about what the “deterministic mode” actually does.

Examples

>>> import imgaug.augmenters as iaa
>>> aug = iaa.MultiplySaturation((0.5, 1.5))

Multiply the saturation channel of images using random values between 0.5 and 1.5.

Methods

__call__(self, *args, **kwargs) Alias for augment().
augment(self[, return_batch, hooks]) Augment a batch.
augment_batch(self, batch[, hooks]) Deprecated.
augment_batch_(self, batch[, parents, hooks]) Augment a single batch in-place.
augment_batches(self, batches[, hooks, …]) Augment multiple batches.
augment_bounding_boxes(self, …[, parents, …]) Augment a batch of bounding boxes.
augment_heatmaps(self, heatmaps[, parents, …]) Augment a batch of heatmaps.
augment_image(self, image[, hooks]) Augment a single image.
augment_images(self, images[, parents, hooks]) Augment a batch of images.
augment_keypoints(self, keypoints_on_images) Augment a batch of keypoints/landmarks.
augment_line_strings(self, …[, parents, hooks]) Augment a batch of line strings.
augment_polygons(self, polygons_on_images[, …]) Augment a batch of polygons.
augment_segmentation_maps(self, segmaps[, …]) Augment a batch of segmentation maps.
copy(self) Create a shallow copy of this Augmenter instance.
copy_random_state(self, source[, recursive, …]) Copy the RNGs from a source augmenter sequence.
copy_random_state_(self, source[, …]) Copy the RNGs from a source augmenter sequence (in-place).
deepcopy(self) Create a deep copy of this Augmenter instance.
draw_grid(self, images, rows, cols) Augment images and draw the results as a single grid-like image.
find_augmenters(self, func[, parents, flat]) Find augmenters that match a condition.
find_augmenters_by_name(self, name[, regex, …]) Find augmenter(s) by name.
find_augmenters_by_names(self, names[, …]) Find augmenter(s) by names.
get_all_children(self[, flat]) Get all children of this augmenter as a list.
get_children_lists(self) See get_children_lists().
get_parameters(self) See get_parameters().
localize_random_state(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
localize_random_state_(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
pool(self[, processes, maxtasksperchild, seed]) Create a pool used for multicore augmentation.
remove_augmenters(self, func[, copy, …]) Remove this augmenter or children that match a condition.
remove_augmenters_(self, func[, parents]) Remove in-place children of this augmenter that match a condition.
remove_augmenters_inplace(self, func[, parents]) Deprecated.
reseed(self[, random_state, deterministic_too]) Deprecated.
seed_(self[, entropy, deterministic_too]) Seed this augmenter and all of its children.
show_grid(self, images, rows, cols) Augment images and plot the results as a single grid-like image.
to_deterministic(self[, n]) Convert this augmenter from a stochastic to a deterministic one.
class imgaug.augmenters.color.Posterize(nb_bits=(1, 8), from_colorspace='RGB', to_colorspace=None, max_size=None, interpolation='linear', seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.color.UniformColorQuantizationToNBits

Alias for UniformColorQuantizationToNBits.

Added in 0.4.0.

Supported dtypes:

See UniformColorQuantizationToNBits.

Methods

__call__(self, *args, **kwargs) Alias for augment().
augment(self[, return_batch, hooks]) Augment a batch.
augment_batch(self, batch[, hooks]) Deprecated.
augment_batch_(self, batch[, parents, hooks]) Augment a single batch in-place.
augment_batches(self, batches[, hooks, …]) Augment multiple batches.
augment_bounding_boxes(self, …[, parents, …]) Augment a batch of bounding boxes.
augment_heatmaps(self, heatmaps[, parents, …]) Augment a batch of heatmaps.
augment_image(self, image[, hooks]) Augment a single image.
augment_images(self, images[, parents, hooks]) Augment a batch of images.
augment_keypoints(self, keypoints_on_images) Augment a batch of keypoints/landmarks.
augment_line_strings(self, …[, parents, hooks]) Augment a batch of line strings.
augment_polygons(self, polygons_on_images[, …]) Augment a batch of polygons.
augment_segmentation_maps(self, segmaps[, …]) Augment a batch of segmentation maps.
copy(self) Create a shallow copy of this Augmenter instance.
copy_random_state(self, source[, recursive, …]) Copy the RNGs from a source augmenter sequence.
copy_random_state_(self, source[, …]) Copy the RNGs from a source augmenter sequence (in-place).
deepcopy(self) Create a deep copy of this Augmenter instance.
draw_grid(self, images, rows, cols) Augment images and draw the results as a single grid-like image.
find_augmenters(self, func[, parents, flat]) Find augmenters that match a condition.
find_augmenters_by_name(self, name[, regex, …]) Find augmenter(s) by name.
find_augmenters_by_names(self, names[, …]) Find augmenter(s) by names.
get_all_children(self[, flat]) Get all children of this augmenter as a list.
get_children_lists(self) Get a list of lists of children of this augmenter.
get_parameters(self) See get_parameters().
localize_random_state(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
localize_random_state_(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
pool(self[, processes, maxtasksperchild, seed]) Create a pool used for multicore augmentation.
remove_augmenters(self, func[, copy, …]) Remove this augmenter or children that match a condition.
remove_augmenters_(self, func[, parents]) Remove in-place children of this augmenter that match a condition.
remove_augmenters_inplace(self, func[, parents]) Deprecated.
reseed(self[, random_state, deterministic_too]) Deprecated.
seed_(self[, entropy, deterministic_too]) Seed this augmenter and all of its children.
show_grid(self, images, rows, cols) Augment images and plot the results as a single grid-like image.
to_deterministic(self[, n]) Convert this augmenter from a stochastic to a deterministic one.
class imgaug.augmenters.color.RemoveSaturation(mul=1, from_colorspace='RGB', seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.color.MultiplySaturation

Decrease the saturation of images by varying degrees.

This creates images looking similar to Grayscale.

This augmenter is the same as MultiplySaturation((0.0, 1.0)).

Added in 0.4.0.

Supported dtypes:

See MultiplySaturation.

Parameters:
  • mul (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – Inverse multiplier to use for the saturation values. High values denote stronger color removal. E.g. 1.0 will remove all saturation, 0.0 will remove nothing. Expected value range is [0.0, 1.0].

    • If a number, then that value will be used for all images.
    • If a tuple (a, b), then a value from the continuous range [a, b] will be sampled per image.
    • If a list, then a random value will be sampled from that list per image.
    • If a StochasticParameter, then a value will be sampled from that parameter per image.
  • from_colorspace (str, optional) – See change_colorspace_().

  • seed (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – See __init__().

  • name (None or str, optional) – See __init__().

  • random_state (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – Old name for parameter seed. Its usage will not yet cause a deprecation warning, but it is still recommended to use seed now. Outdated since 0.4.0.

  • deterministic (bool, optional) – Deprecated since 0.4.0. See method to_deterministic() for an alternative and for details about what the “deterministic mode” actually does.

Examples

>>> import imgaug.augmenters as iaa
>>> aug = iaa.RemoveSaturation((0.0, 1.0))

Create an augmenter that decreases saturation by varying degrees.

>>> aug = iaa.RemoveSaturation(1.0)

Create an augmenter that removes all saturation from input images. This is similar to Grayscale.

>>> aug = iaa.RemoveSaturation(from_colorspace=iaa.CSPACE_BGR)

Create an augmenter that decreases saturation of images in BGR colorspace by varying degrees.

Methods

__call__(self, *args, **kwargs) Alias for augment().
augment(self[, return_batch, hooks]) Augment a batch.
augment_batch(self, batch[, hooks]) Deprecated.
augment_batch_(self, batch[, parents, hooks]) Augment a single batch in-place.
augment_batches(self, batches[, hooks, …]) Augment multiple batches.
augment_bounding_boxes(self, …[, parents, …]) Augment a batch of bounding boxes.
augment_heatmaps(self, heatmaps[, parents, …]) Augment a batch of heatmaps.
augment_image(self, image[, hooks]) Augment a single image.
augment_images(self, images[, parents, hooks]) Augment a batch of images.
augment_keypoints(self, keypoints_on_images) Augment a batch of keypoints/landmarks.
augment_line_strings(self, …[, parents, hooks]) Augment a batch of line strings.
augment_polygons(self, polygons_on_images[, …]) Augment a batch of polygons.
augment_segmentation_maps(self, segmaps[, …]) Augment a batch of segmentation maps.
copy(self) Create a shallow copy of this Augmenter instance.
copy_random_state(self, source[, recursive, …]) Copy the RNGs from a source augmenter sequence.
copy_random_state_(self, source[, …]) Copy the RNGs from a source augmenter sequence (in-place).
deepcopy(self) Create a deep copy of this Augmenter instance.
draw_grid(self, images, rows, cols) Augment images and draw the results as a single grid-like image.
find_augmenters(self, func[, parents, flat]) Find augmenters that match a condition.
find_augmenters_by_name(self, name[, regex, …]) Find augmenter(s) by name.
find_augmenters_by_names(self, names[, …]) Find augmenter(s) by names.
get_all_children(self[, flat]) Get all children of this augmenter as a list.
get_children_lists(self) See get_children_lists().
get_parameters(self) See get_parameters().
localize_random_state(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
localize_random_state_(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
pool(self[, processes, maxtasksperchild, seed]) Create a pool used for multicore augmentation.
remove_augmenters(self, func[, copy, …]) Remove this augmenter or children that match a condition.
remove_augmenters_(self, func[, parents]) Remove in-place children of this augmenter that match a condition.
remove_augmenters_inplace(self, func[, parents]) Deprecated.
reseed(self[, random_state, deterministic_too]) Deprecated.
seed_(self[, entropy, deterministic_too]) Seed this augmenter and all of its children.
show_grid(self, images, rows, cols) Augment images and plot the results as a single grid-like image.
to_deterministic(self[, n]) Convert this augmenter from a stochastic to a deterministic one.
class imgaug.augmenters.color.UniformColorQuantization(n_colors=(2, 16), from_colorspace='RGB', to_colorspace=None, max_size=None, interpolation='linear', seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.color._AbstractColorQuantization

Quantize colors into N bins with regular distance.

For uint8 images the equation is floor(v/q)*q + q/2 with q = 256/N, where v is a pixel intensity value and N is the target number of colors after quantization.

This augmenter is faster than KMeansColorQuantization, but the set of possible output colors is constant (i.e. independent of the input images). It may produce unsatisfying outputs for input images that are made up of very similar colors.

Note

This augmenter expects input images to be either grayscale or to have 3 or 4 channels and use colorspace from_colorspace. If images have 4 channels, it is assumed that the 4th channel is an alpha channel and it will not be quantized.

Supported dtypes:

if (image size <= max_size):

if (image size > max_size):

Parameters:
  • n_colors (int or tuple of int or list of int or imgaug.parameters.StochasticParameter, optional) –

    Target number of colors to use in the generated output image.

    • If a number, exactly that value will always be used.
    • If a tuple (a, b), then a value from the discrete interval [a..b] will be sampled per image.
    • If a list, then a random value will be sampled from that list per image.
    • If a StochasticParameter, then a value will be sampled per image from that parameter.
  • to_colorspace (None or str or list of str or imgaug.parameters.StochasticParameter) – The colorspace in which to perform the quantization. See change_colorspace_() for valid values. This will be ignored for grayscale input images.

    • If None the colorspace of input images will not be changed.
    • If a string, it must be among the allowed colorspaces.
    • If a list, it is expected to be a list of strings, each one being an allowed colorspace. A random element from the list will be chosen per image.
    • If a StochasticParameter, it is expected to return string. A new sample will be drawn per image.
  • from_colorspace (str, optional) – The colorspace of the input images. See to_colorspace. Only a single string is allowed.

  • max_size (None or int, optional) – Maximum image size at which to perform the augmentation. If the width or height of an image exceeds this value, it will be downscaled before running the augmentation so that the longest side matches max_size. This is done to speed up the augmentation. The final output image has the same size as the input image. Use None to apply no downscaling.

  • interpolation (int or str, optional) – Interpolation method to use during downscaling when max_size is exceeded. Valid methods are the same as in imresize_single_image().

  • seed (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – See __init__().

  • name (None or str, optional) – See __init__().

  • random_state (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – Old name for parameter seed. Its usage will not yet cause a deprecation warning, but it is still recommended to use seed now. Outdated since 0.4.0.

  • deterministic (bool, optional) – Deprecated since 0.4.0. See method to_deterministic() for an alternative and for details about what the “deterministic mode” actually does.

Examples

>>> import imgaug.augmenters as iaa
>>> aug = iaa.UniformColorQuantization()

Create an augmenter to apply uniform color quantization to images using a random amount of colors, sampled uniformly from the discrete interval [2..16].

>>> aug = iaa.UniformColorQuantization(n_colors=8)

Create an augmenter that quantizes images to (up to) eight colors.

>>> aug = iaa.UniformColorQuantization(n_colors=(4, 16))

Create an augmenter that quantizes images to (up to) n colors, where n is randomly and uniformly sampled from the discrete interval [4..16].

>>> aug = iaa.UniformColorQuantization(
>>>     from_colorspace=iaa.CSPACE_BGR,
>>>     to_colorspace=[iaa.CSPACE_RGB, iaa.CSPACE_HSV])

Create an augmenter that uniformly quantizes images in either RGB or HSV colorspace (randomly picked per image). The input colorspace of all images has to be BGR.

Attributes:
n_colors

Alias for property counts.

Methods

__call__(self, *args, **kwargs) Alias for augment().
augment(self[, return_batch, hooks]) Augment a batch.
augment_batch(self, batch[, hooks]) Deprecated.
augment_batch_(self, batch[, parents, hooks]) Augment a single batch in-place.
augment_batches(self, batches[, hooks, …]) Augment multiple batches.
augment_bounding_boxes(self, …[, parents, …]) Augment a batch of bounding boxes.
augment_heatmaps(self, heatmaps[, parents, …]) Augment a batch of heatmaps.
augment_image(self, image[, hooks]) Augment a single image.
augment_images(self, images[, parents, hooks]) Augment a batch of images.
augment_keypoints(self, keypoints_on_images) Augment a batch of keypoints/landmarks.
augment_line_strings(self, …[, parents, hooks]) Augment a batch of line strings.
augment_polygons(self, polygons_on_images[, …]) Augment a batch of polygons.
augment_segmentation_maps(self, segmaps[, …]) Augment a batch of segmentation maps.
copy(self) Create a shallow copy of this Augmenter instance.
copy_random_state(self, source[, recursive, …]) Copy the RNGs from a source augmenter sequence.
copy_random_state_(self, source[, …]) Copy the RNGs from a source augmenter sequence (in-place).
deepcopy(self) Create a deep copy of this Augmenter instance.
draw_grid(self, images, rows, cols) Augment images and draw the results as a single grid-like image.
find_augmenters(self, func[, parents, flat]) Find augmenters that match a condition.
find_augmenters_by_name(self, name[, regex, …]) Find augmenter(s) by name.
find_augmenters_by_names(self, names[, …]) Find augmenter(s) by names.
get_all_children(self[, flat]) Get all children of this augmenter as a list.
get_children_lists(self) Get a list of lists of children of this augmenter.
get_parameters(self) See get_parameters().
localize_random_state(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
localize_random_state_(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
pool(self[, processes, maxtasksperchild, seed]) Create a pool used for multicore augmentation.
remove_augmenters(self, func[, copy, …]) Remove this augmenter or children that match a condition.
remove_augmenters_(self, func[, parents]) Remove in-place children of this augmenter that match a condition.
remove_augmenters_inplace(self, func[, parents]) Deprecated.
reseed(self[, random_state, deterministic_too]) Deprecated.
seed_(self[, entropy, deterministic_too]) Seed this augmenter and all of its children.
show_grid(self, images, rows, cols) Augment images and plot the results as a single grid-like image.
to_deterministic(self[, n]) Convert this augmenter from a stochastic to a deterministic one.
n_colors

Alias for property counts.

Added in 0.4.0.

class imgaug.augmenters.color.UniformColorQuantizationToNBits(nb_bits=(1, 8), from_colorspace='RGB', to_colorspace=None, max_size=None, interpolation='linear', seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.color._AbstractColorQuantization

Quantize images by setting 8-B bits of each component to zero.

This augmenter sets the 8-B highest frequency (rightmost) bits of each array component to zero. For B bits this is equivalent to changing each component’s intensity value v to v' = v & (2**(8-B) - 1), e.g. for B=3 this results in v' = c & ~(2**(3-1) - 1) = c & ~3 = c & ~0000 0011 = c & 1111 1100.

This augmenter behaves for B similarly to UniformColorQuantization(2**B), but quantizes each bin with interval (a, b) to a instead of to a + (b-a)/2.

This augmenter is comparable to PIL.ImageOps.posterize().

Note

This augmenter expects input images to be either grayscale or to have 3 or 4 channels and use colorspace from_colorspace. If images have 4 channels, it is assumed that the 4th channel is an alpha channel and it will not be quantized.

Added in 0.4.0.

Supported dtypes:

if (image size <= max_size):

if (image size > max_size):

Parameters:
  • nb_bits (int or tuple of int or list of int or imgaug.parameters.StochasticParameter, optional) –

    Number of bits to keep in each image’s array component.

    • If a number, exactly that value will always be used.
    • If a tuple (a, b), then a value from the discrete interval [a..b] will be sampled per image.
    • If a list, then a random value will be sampled from that list per image.
    • If a StochasticParameter, then a value will be sampled per image from that parameter.
  • to_colorspace (None or str or list of str or imgaug.parameters.StochasticParameter) – The colorspace in which to perform the quantization. See change_colorspace_() for valid values. This will be ignored for grayscale input images.

    • If None the colorspace of input images will not be changed.
    • If a string, it must be among the allowed colorspaces.
    • If a list, it is expected to be a list of strings, each one being an allowed colorspace. A random element from the list will be chosen per image.
    • If a StochasticParameter, it is expected to return string. A new sample will be drawn per image.
  • from_colorspace (str, optional) – The colorspace of the input images. See to_colorspace. Only a single string is allowed.

  • max_size (None or int, optional) – Maximum image size at which to perform the augmentation. If the width or height of an image exceeds this value, it will be downscaled before running the augmentation so that the longest side matches max_size. This is done to speed up the augmentation. The final output image has the same size as the input image. Use None to apply no downscaling.

  • interpolation (int or str, optional) – Interpolation method to use during downscaling when max_size is exceeded. Valid methods are the same as in imresize_single_image().

  • seed (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – See __init__().

  • name (None or str, optional) – See __init__().

  • random_state (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – Old name for parameter seed. Its usage will not yet cause a deprecation warning, but it is still recommended to use seed now. Outdated since 0.4.0.

  • deterministic (bool, optional) – Deprecated since 0.4.0. See method to_deterministic() for an alternative and for details about what the “deterministic mode” actually does.

Examples

>>> import imgaug.augmenters as iaa
>>> aug = iaa.UniformColorQuantizationToNBits()

Create an augmenter to apply uniform color quantization to images using a random amount of bits to remove, sampled uniformly from the discrete interval [1..8].

>>> aug = iaa.UniformColorQuantizationToNBits(nb_bits=(2, 8))

Create an augmenter that quantizes images by removing 8-B rightmost bits from each component, where B is uniformly sampled from the discrete interval [2..8].

>>> aug = iaa.UniformColorQuantizationToNBits(
>>>     from_colorspace=iaa.CSPACE_BGR,
>>>     to_colorspace=[iaa.CSPACE_RGB, iaa.CSPACE_HSV])

Create an augmenter that uniformly quantizes images in either RGB or HSV colorspace (randomly picked per image). The input colorspace of all images has to be BGR.

Methods

__call__(self, *args, **kwargs) Alias for augment().
augment(self[, return_batch, hooks]) Augment a batch.
augment_batch(self, batch[, hooks]) Deprecated.
augment_batch_(self, batch[, parents, hooks]) Augment a single batch in-place.
augment_batches(self, batches[, hooks, …]) Augment multiple batches.
augment_bounding_boxes(self, …[, parents, …]) Augment a batch of bounding boxes.
augment_heatmaps(self, heatmaps[, parents, …]) Augment a batch of heatmaps.
augment_image(self, image[, hooks]) Augment a single image.
augment_images(self, images[, parents, hooks]) Augment a batch of images.
augment_keypoints(self, keypoints_on_images) Augment a batch of keypoints/landmarks.
augment_line_strings(self, …[, parents, hooks]) Augment a batch of line strings.
augment_polygons(self, polygons_on_images[, …]) Augment a batch of polygons.
augment_segmentation_maps(self, segmaps[, …]) Augment a batch of segmentation maps.
copy(self) Create a shallow copy of this Augmenter instance.
copy_random_state(self, source[, recursive, …]) Copy the RNGs from a source augmenter sequence.
copy_random_state_(self, source[, …]) Copy the RNGs from a source augmenter sequence (in-place).
deepcopy(self) Create a deep copy of this Augmenter instance.
draw_grid(self, images, rows, cols) Augment images and draw the results as a single grid-like image.
find_augmenters(self, func[, parents, flat]) Find augmenters that match a condition.
find_augmenters_by_name(self, name[, regex, …]) Find augmenter(s) by name.
find_augmenters_by_names(self, names[, …]) Find augmenter(s) by names.
get_all_children(self[, flat]) Get all children of this augmenter as a list.
get_children_lists(self) Get a list of lists of children of this augmenter.
get_parameters(self) See get_parameters().
localize_random_state(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
localize_random_state_(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
pool(self[, processes, maxtasksperchild, seed]) Create a pool used for multicore augmentation.
remove_augmenters(self, func[, copy, …]) Remove this augmenter or children that match a condition.
remove_augmenters_(self, func[, parents]) Remove in-place children of this augmenter that match a condition.
remove_augmenters_inplace(self, func[, parents]) Deprecated.
reseed(self[, random_state, deterministic_too]) Deprecated.
seed_(self[, entropy, deterministic_too]) Seed this augmenter and all of its children.
show_grid(self, images, rows, cols) Augment images and plot the results as a single grid-like image.
to_deterministic(self[, n]) Convert this augmenter from a stochastic to a deterministic one.
class imgaug.augmenters.color.WithBrightnessChannels(children=None, to_colorspace=['YCrCb', 'HSV', 'HLS', 'Lab', 'Luv', 'YUV'], from_colorspace='RGB', seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.meta.Augmenter

Augmenter to apply child augmenters to brightness-related image channels.

This augmenter first converts an image to a random colorspace containing a brightness-related channel (e.g. V in HSV), then extracts that channel and applies its child augmenters to this one channel. Afterwards, it reintegrates the augmented channel into the full image and converts back to the input colorspace.

Added in 0.4.0.

Supported dtypes:

See change_colorspaces_().

Parameters:
  • children (imgaug.augmenters.meta.Augmenter or list of imgaug.augmenters.meta.Augmenter or None, optional) – One or more augmenters to apply to the brightness channels. They receive images with a single channel and have to modify these.

  • to_colorspace (imgaug.ALL or str or list of str or imgaug.parameters.StochasticParameter, optional) – Colorspace in which to extract the brightness-related channels. Currently, imgaug.augmenters.color.CSPACE_YCrCb, CSPACE_HSV, CSPACE_HLS, CSPACE_Lab, CSPACE_Luv, CSPACE_YUV, CSPACE_CIE are supported.

    • If imgaug.ALL: Will pick imagewise a random colorspace from all supported colorspaces.
    • If str: Will always use this colorspace.
    • If list or str: Will pick imagewise a random colorspace from this list.
    • If StochasticParameter: A parameter that will be queried once per batch to generate all target colorspaces. Expected to return strings matching the CSPACE_* constants.
  • from_colorspace (str, optional) – See change_colorspace_().

  • seed (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – See __init__().

  • name (None or str, optional) – See __init__().

  • random_state (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – Old name for parameter seed. Its usage will not yet cause a deprecation warning, but it is still recommended to use seed now. Outdated since 0.4.0.

  • deterministic (bool, optional) – Deprecated since 0.4.0. See method to_deterministic() for an alternative and for details about what the “deterministic mode” actually does.

Examples

>>> import imgaug.augmenters as iaa
>>> aug = iaa.WithBrightnessChannels(iaa.Add((-50, 50)))

Add -50 to 50 to the brightness-related channels of each image.

>>> aug = iaa.WithBrightnessChannels(
>>>     iaa.Add((-50, 50)), to_colorspace=[iaa.CSPACE_Lab, iaa.CSPACE_HSV])

Add -50 to 50 to the brightness-related channels of each image, but pick those brightness-related channels only from Lab (L) and HSV (V) colorspaces.

>>> aug = iaa.WithBrightnessChannels(
>>>     iaa.Add((-50, 50)), from_colorspace=iaa.CSPACE_BGR)

Add -50 to 50 to the brightness-related channels of each image, where the images are provided in BGR colorspace instead of the standard RGB.

Methods

__call__(self, *args, **kwargs) Alias for augment().
augment(self[, return_batch, hooks]) Augment a batch.
augment_batch(self, batch[, hooks]) Deprecated.
augment_batch_(self, batch[, parents, hooks]) Augment a single batch in-place.
augment_batches(self, batches[, hooks, …]) Augment multiple batches.
augment_bounding_boxes(self, …[, parents, …]) Augment a batch of bounding boxes.
augment_heatmaps(self, heatmaps[, parents, …]) Augment a batch of heatmaps.
augment_image(self, image[, hooks]) Augment a single image.
augment_images(self, images[, parents, hooks]) Augment a batch of images.
augment_keypoints(self, keypoints_on_images) Augment a batch of keypoints/landmarks.
augment_line_strings(self, …[, parents, hooks]) Augment a batch of line strings.
augment_polygons(self, polygons_on_images[, …]) Augment a batch of polygons.
augment_segmentation_maps(self, segmaps[, …]) Augment a batch of segmentation maps.
copy(self) Create a shallow copy of this Augmenter instance.
copy_random_state(self, source[, recursive, …]) Copy the RNGs from a source augmenter sequence.
copy_random_state_(self, source[, …]) Copy the RNGs from a source augmenter sequence (in-place).
deepcopy(self) Create a deep copy of this Augmenter instance.
draw_grid(self, images, rows, cols) Augment images and draw the results as a single grid-like image.
find_augmenters(self, func[, parents, flat]) Find augmenters that match a condition.
find_augmenters_by_name(self, name[, regex, …]) Find augmenter(s) by name.
find_augmenters_by_names(self, names[, …]) Find augmenter(s) by names.
get_all_children(self[, flat]) Get all children of this augmenter as a list.
get_children_lists(self) See get_children_lists().
get_parameters(self) See get_parameters().
localize_random_state(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
localize_random_state_(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
pool(self[, processes, maxtasksperchild, seed]) Create a pool used for multicore augmentation.
remove_augmenters(self, func[, copy, …]) Remove this augmenter or children that match a condition.
remove_augmenters_(self, func[, parents]) Remove in-place children of this augmenter that match a condition.
remove_augmenters_inplace(self, func[, parents]) Deprecated.
reseed(self[, random_state, deterministic_too]) Deprecated.
seed_(self[, entropy, deterministic_too]) Seed this augmenter and all of its children.
show_grid(self, images, rows, cols) Augment images and plot the results as a single grid-like image.
to_deterministic(self[, n]) Convert this augmenter from a stochastic to a deterministic one.
get_children_lists(self)[source]

See get_children_lists().

get_parameters(self)[source]

See get_parameters().

class imgaug.augmenters.color.WithColorspace(to_colorspace, from_colorspace='RGB', children=None, seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.meta.Augmenter

Apply child augmenters within a specific colorspace.

This augumenter takes a source colorspace A and a target colorspace B as well as children C. It changes images from A to B, then applies the child augmenters C and finally changes the colorspace back from B to A. See also ChangeColorspace() for more.

Supported dtypes:

See change_colorspaces_().

Parameters:
  • to_colorspace (str) – See change_colorspace_().
  • from_colorspace (str, optional) – See change_colorspace_().
  • children (imgaug.augmenters.meta.Augmenter or list of imgaug.augmenters.meta.Augmenter or None, optional) – One or more augmenters to apply to converted images.
  • seed (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – See __init__().
  • name (None or str, optional) – See __init__().
  • random_state (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – Old name for parameter seed. Its usage will not yet cause a deprecation warning, but it is still recommended to use seed now. Outdated since 0.4.0.
  • deterministic (bool, optional) – Deprecated since 0.4.0. See method to_deterministic() for an alternative and for details about what the “deterministic mode” actually does.

Examples

>>> import imgaug.augmenters as iaa
>>> aug = iaa.WithColorspace(
>>>     to_colorspace=iaa.CSPACE_HSV,
>>>     from_colorspace=iaa.CSPACE_RGB,
>>>     children=iaa.WithChannels(
>>>         0,
>>>         iaa.Add((0, 50))
>>>     )
>>> )

Convert to HSV colorspace, add a value between 0 and 50 (uniformly sampled per image) to the Hue channel, then convert back to the input colorspace (RGB).

Methods

__call__(self, *args, **kwargs) Alias for augment().
augment(self[, return_batch, hooks]) Augment a batch.
augment_batch(self, batch[, hooks]) Deprecated.
augment_batch_(self, batch[, parents, hooks]) Augment a single batch in-place.
augment_batches(self, batches[, hooks, …]) Augment multiple batches.
augment_bounding_boxes(self, …[, parents, …]) Augment a batch of bounding boxes.
augment_heatmaps(self, heatmaps[, parents, …]) Augment a batch of heatmaps.
augment_image(self, image[, hooks]) Augment a single image.
augment_images(self, images[, parents, hooks]) Augment a batch of images.
augment_keypoints(self, keypoints_on_images) Augment a batch of keypoints/landmarks.
augment_line_strings(self, …[, parents, hooks]) Augment a batch of line strings.
augment_polygons(self, polygons_on_images[, …]) Augment a batch of polygons.
augment_segmentation_maps(self, segmaps[, …]) Augment a batch of segmentation maps.
copy(self) Create a shallow copy of this Augmenter instance.
copy_random_state(self, source[, recursive, …]) Copy the RNGs from a source augmenter sequence.
copy_random_state_(self, source[, …]) Copy the RNGs from a source augmenter sequence (in-place).
deepcopy(self) Create a deep copy of this Augmenter instance.
draw_grid(self, images, rows, cols) Augment images and draw the results as a single grid-like image.
find_augmenters(self, func[, parents, flat]) Find augmenters that match a condition.
find_augmenters_by_name(self, name[, regex, …]) Find augmenter(s) by name.
find_augmenters_by_names(self, names[, …]) Find augmenter(s) by names.
get_all_children(self[, flat]) Get all children of this augmenter as a list.
get_children_lists(self) See get_children_lists().
get_parameters(self) See get_parameters().
localize_random_state(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
localize_random_state_(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
pool(self[, processes, maxtasksperchild, seed]) Create a pool used for multicore augmentation.
remove_augmenters(self, func[, copy, …]) Remove this augmenter or children that match a condition.
remove_augmenters_(self, func[, parents]) Remove in-place children of this augmenter that match a condition.
remove_augmenters_inplace(self, func[, parents]) Deprecated.
reseed(self[, random_state, deterministic_too]) Deprecated.
seed_(self[, entropy, deterministic_too]) Seed this augmenter and all of its children.
show_grid(self, images, rows, cols) Augment images and plot the results as a single grid-like image.
to_deterministic(self[, n]) Convert this augmenter from a stochastic to a deterministic one.
get_children_lists(self)[source]

See get_children_lists().

get_parameters(self)[source]

See get_parameters().

class imgaug.augmenters.color.WithHueAndSaturation(children=None, from_colorspace='RGB', seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.meta.Augmenter

Apply child augmenters to hue and saturation channels.

This augumenter takes an image in a source colorspace, converts it to HSV, extracts the H (hue) and S (saturation) channels, applies the provided child augmenters to these channels and finally converts back to the original colorspace.

The image array generated by this augmenter and provided to its children is in int16 (sic! only augmenters that can handle int16 arrays can be children!). The hue channel is mapped to the value range [0, 255]. Before converting back to the source colorspace, the saturation channel’s values are clipped to [0, 255]. A modulo operation is applied to the hue channel’s values, followed by a mapping from [0, 255] to [0, 180] (and finally the colorspace conversion).

Supported dtypes:

See change_colorspaces_().

Parameters:
  • from_colorspace (str, optional) – See change_colorspace_().
  • children (imgaug.augmenters.meta.Augmenter or list of imgaug.augmenters.meta.Augmenter or None, optional) – One or more augmenters to apply to converted images. They receive int16 images with two channels (hue, saturation) and have to modify these.
  • seed (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – See __init__().
  • name (None or str, optional) – See __init__().
  • random_state (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – Old name for parameter seed. Its usage will not yet cause a deprecation warning, but it is still recommended to use seed now. Outdated since 0.4.0.
  • deterministic (bool, optional) – Deprecated since 0.4.0. See method to_deterministic() for an alternative and for details about what the “deterministic mode” actually does.

Examples

>>> import imgaug.augmenters as iaa
>>> aug = iaa.WithHueAndSaturation(
>>>     iaa.WithChannels(0, iaa.Add((0, 50)))
>>> )

Create an augmenter that will add a random value between 0 and 50 (uniformly sampled per image) hue channel in HSV colorspace. It automatically accounts for the hue being in angular representation, i.e. if the angle goes beyond 360 degrees, it will start again at 0 degrees. The colorspace is finally converted back to RGB (default setting).

>>> import imgaug.augmenters as iaa
>>> aug = iaa.WithHueAndSaturation([
>>>     iaa.WithChannels(0, iaa.Add((-30, 10))),
>>>     iaa.WithChannels(1, [
>>>         iaa.Multiply((0.5, 1.5)),
>>>         iaa.LinearContrast((0.75, 1.25))
>>>     ])
>>> ])

Create an augmenter that adds a random value sampled uniformly from the range [-30, 10] to the hue and multiplies the saturation by a random factor sampled uniformly from [0.5, 1.5]. It also modifies the contrast of the saturation channel. After these steps, the HSV image is converted back to RGB.

Methods

__call__(self, *args, **kwargs) Alias for augment().
augment(self[, return_batch, hooks]) Augment a batch.
augment_batch(self, batch[, hooks]) Deprecated.
augment_batch_(self, batch[, parents, hooks]) Augment a single batch in-place.
augment_batches(self, batches[, hooks, …]) Augment multiple batches.
augment_bounding_boxes(self, …[, parents, …]) Augment a batch of bounding boxes.
augment_heatmaps(self, heatmaps[, parents, …]) Augment a batch of heatmaps.
augment_image(self, image[, hooks]) Augment a single image.
augment_images(self, images[, parents, hooks]) Augment a batch of images.
augment_keypoints(self, keypoints_on_images) Augment a batch of keypoints/landmarks.
augment_line_strings(self, …[, parents, hooks]) Augment a batch of line strings.
augment_polygons(self, polygons_on_images[, …]) Augment a batch of polygons.
augment_segmentation_maps(self, segmaps[, …]) Augment a batch of segmentation maps.
copy(self) Create a shallow copy of this Augmenter instance.
copy_random_state(self, source[, recursive, …]) Copy the RNGs from a source augmenter sequence.
copy_random_state_(self, source[, …]) Copy the RNGs from a source augmenter sequence (in-place).
deepcopy(self) Create a deep copy of this Augmenter instance.
draw_grid(self, images, rows, cols) Augment images and draw the results as a single grid-like image.
find_augmenters(self, func[, parents, flat]) Find augmenters that match a condition.
find_augmenters_by_name(self, name[, regex, …]) Find augmenter(s) by name.
find_augmenters_by_names(self, names[, …]) Find augmenter(s) by names.
get_all_children(self[, flat]) Get all children of this augmenter as a list.
get_children_lists(self) See get_children_lists().
get_parameters(self) See get_parameters().
localize_random_state(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
localize_random_state_(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
pool(self[, processes, maxtasksperchild, seed]) Create a pool used for multicore augmentation.
remove_augmenters(self, func[, copy, …]) Remove this augmenter or children that match a condition.
remove_augmenters_(self, func[, parents]) Remove in-place children of this augmenter that match a condition.
remove_augmenters_inplace(self, func[, parents]) Deprecated.
reseed(self[, random_state, deterministic_too]) Deprecated.
seed_(self[, entropy, deterministic_too]) Seed this augmenter and all of its children.
show_grid(self, images, rows, cols) Augment images and plot the results as a single grid-like image.
to_deterministic(self[, n]) Convert this augmenter from a stochastic to a deterministic one.
get_children_lists(self)[source]

See get_children_lists().

get_parameters(self)[source]

See get_parameters().

imgaug.augmenters.color.change_color_temperature(image, kelvin, from_colorspace='RGB')[source]

Change the temperature of an image to a given value in Kelvin.

Added in 0.4.0.

Supported dtypes:

See change_color_temperatures_.

Parameters:
  • image (ndarray) – The image which’s color temperature is supposed to be changed. Expected to be of shape (H,W,3) array.
  • kelvin (number) – The temperature in Kelvin. Expected value range is in the interval (1000, 4000).
  • from_colorspace (str, optional) – The source colorspace. See change_colorspaces_(). Defaults to RGB.
Returns:

Image with target color temperature.

Return type:

ndarray

imgaug.augmenters.color.change_color_temperatures_(images, kelvins, from_colorspaces='RGB')[source]

Change in-place the temperature of images to given values in Kelvin.

Added in 0.4.0.

Supported dtypes:

See change_colorspace_.

Parameters:
  • images (ndarray or list of ndarray) – The images which’s color temperature is supposed to be changed. Either a list of (H,W,3) arrays or a single (N,H,W,3) array.
  • kelvins (iterable of number) – Temperatures in Kelvin. One per image. Expected value range is in the interval (1000, 4000).
  • from_colorspaces (str or list of str, optional) – The source colorspace. See change_colorspaces_(). Defaults to RGB.
Returns:

Images with target color temperatures. The input array(s) might have been changed in-place.

Return type:

ndarray or list of ndarray

imgaug.augmenters.color.change_colorspace_(image, to_colorspace, from_colorspace='RGB')[source]

Change the colorspace of an image inplace.

Note

All outputs of this function are uint8. For some colorspaces this may not be optimal.

Note

Output grayscale images will still have three channels.

Supported dtypes:

  • uint8: yes; fully tested
  • uint16: no
  • uint32: no
  • uint64: no
  • int8: no
  • int16: no
  • int32: no
  • int64: no
  • float16: no
  • float32: no
  • float64: no
  • float128: no
  • bool: no
Parameters:
  • image (ndarray) – The image to convert from one colorspace into another. Usually expected to have shape (H,W,3).
  • to_colorspace (str) – The target colorspace. See the CSPACE constants, e.g. imgaug.augmenters.color.CSPACE_RGB.
  • from_colorspace (str, optional) – The source colorspace. Analogous to to_colorspace. Defaults to RGB.
Returns:

Image with target colorspace. Can be the same array instance as was originally provided (i.e. changed inplace). Grayscale images will still have three channels.

Return type:

ndarray

Examples

>>> import imgaug.augmenters as iaa
>>> import numpy as np
>>> # fake RGB image
>>> image_rgb = np.arange(4*4*3).astype(np.uint8).reshape((4, 4, 3))
>>> image_bgr = iaa.change_colorspace_(np.copy(image_rgb), iaa.CSPACE_BGR)
imgaug.augmenters.color.change_colorspaces_(images, to_colorspaces, from_colorspaces='RGB')[source]

Change the colorspaces of a batch of images inplace.

Note

All outputs of this function are uint8. For some colorspaces this may not be optimal.

Note

Output grayscale images will still have three channels.

Supported dtypes:

See change_colorspace_().

Parameters:
  • images (ndarray or list of ndarray) – The images to convert from one colorspace into another. Either a list of (H,W,3) arrays or a single (N,H,W,3) array.
  • to_colorspaces (str or iterable of str) – The target colorspaces. Either a single string (all images will be converted to the same colorspace) or an iterable of strings (one per image). See the CSPACE constants, e.g. imgaug.augmenters.color.CSPACE_RGB.
  • from_colorspaces (str or list of str, optional) – The source colorspace. Analogous to to_colorspace. Defaults to RGB.
Returns:

Images with target colorspaces. Can contain the same array instances as were originally provided (i.e. changed inplace). Grayscale images will still have three channels.

Return type:

ndarray or list of ndarray

Examples

>>> import imgaug.augmenters as iaa
>>> import numpy as np
>>> # fake RGB image
>>> image_rgb = np.arange(4*4*3).astype(np.uint8).reshape((4, 4, 3))
>>> images_rgb = [image_rgb, image_rgb, image_rgb]
>>> images_rgb_copy = [np.copy(image_rgb) for image_rgb in images_rgb]
>>> images_bgr = iaa.change_colorspaces_(images_rgb_copy, iaa.CSPACE_BGR)

Create three example RGB images and convert them to BGR colorspace.

>>> images_rgb_copy = [np.copy(image_rgb) for image_rgb in images_rgb]
>>> images_various = iaa.change_colorspaces_(
>>>     images_rgb_copy, [iaa.CSPACE_BGR, iaa.CSPACE_HSV, iaa.CSPACE_GRAY])

Chnage the colorspace of the first image to BGR, the one of the second image to HSV and the one of the third image to grayscale (note that in the latter case the image will still have shape (H,W,3), not (H,W,1)).

imgaug.augmenters.color.posterize(arr, nb_bits)[source]

Alias for quantize_uniform_to_n_bits().

This function is an alias for quantize_uniform_to_n_bits() and was added for users familiar with the same function in PIL.

Added in 0.4.0.

Supported dtypes:

See quantize_uniform_to_n_bits().

Parameters:
Returns:

Array with quantized components.

Return type:

ndarray

imgaug.augmenters.color.quantize_colors_kmeans(image, n_colors, n_max_iter=10, eps=1.0)[source]

Deprecated. Use imgaug.augmenters.colors.quantize_kmeans instead.

Outdated name of quantize_kmeans().

Deprecated since 0.4.0.

imgaug.augmenters.color.quantize_colors_uniform(image, n_colors)[source]

Deprecated. Use imgaug.augmenters.colors.quantize_uniform instead.

Outdated name for quantize_uniform().

Deprecated since 0.4.0.

imgaug.augmenters.color.quantize_kmeans(arr, nb_clusters, nb_max_iter=10, eps=1.0)[source]

Quantize an array into N bins using k-means clustering.

If the input is an image, this method returns in an image with a maximum of N colors. Similar colors are grouped to their mean. The k-means clustering happens across channels and not channelwise.

Code similar to https://docs.opencv.org/3.0-beta/doc/py_tutorials/py_ml/ py_kmeans/py_kmeans_opencv/py_kmeans_opencv.html

Warning

This function currently changes the RNG state of both OpenCV’s internal RNG and imgaug’s global RNG. This is necessary in order to ensure that the k-means clustering happens deterministically.

Added in 0.4.0. (Previously called quantize_colors_kmeans().)

Supported dtypes:

  • uint8: yes; fully tested
  • uint16: no
  • uint32: no
  • uint64: no
  • int8: no
  • int16: no
  • int32: no
  • int64: no
  • float16: no
  • float32: no
  • float64: no
  • float128: no
  • bool: no
Parameters:
  • arr (ndarray) – Array to quantize. Expected to be of shape (H,W) or (H,W,C) with C usually being 1 or 3.
  • nb_clusters (int) – Number of clusters to quantize into, i.e. k in k-means clustering. This corresponds to the maximum number of colors in an output image.
  • nb_max_iter (int, optional) – Maximum number of iterations that the k-means clustering algorithm is run.
  • eps (float, optional) – Minimum change of all clusters per k-means iteration. If all clusters change by less than this amount in an iteration, the clustering is stopped.
Returns:

Image with quantized colors.

Return type:

ndarray

Examples

>>> import imgaug.augmenters as iaa
>>> import numpy as np
>>> image = np.arange(4 * 4 * 3, dtype=np.uint8).reshape((4, 4, 3))
>>> image_quantized = iaa.quantize_kmeans(image, 6)

Generates a 4x4 image with 3 channels, containing consecutive values from 0 to 4*4*3, leading to an equal number of colors. These colors are then quantized so that only 6 are remaining. Note that the six remaining colors do have to appear in the input image.

imgaug.augmenters.color.quantize_uniform(arr, nb_bins, to_bin_centers=True)[source]

Quantize an array into N equally-sized bins.

See quantize_uniform_() for details.

Added in 0.4.0. (Previously called quantize_colors_uniform().)

Supported dtypes:

See quantize_uniform_().

Parameters:
Returns:

Array with quantized components.

Return type:

ndarray

imgaug.augmenters.color.quantize_uniform_(arr, nb_bins, to_bin_centers=True)[source]

Quantize an array into N equally-sized bins in-place.

This can be used to quantize/posterize an image into N colors.

For uint8 arrays the equation is floor(v/q)*q + q/2 with q = 256/N, where v is a pixel intensity value and N is the target number of bins (roughly matches number of colors) after quantization.

Added in 0.4.0.

Supported dtypes:

  • uint8: yes; fully tested
  • uint16: no
  • uint32: no
  • uint64: no
  • int8: no
  • int16: no
  • int32: no
  • int64: no
  • float16: no
  • float32: no
  • float64: no
  • float128: no
  • bool: no
Parameters:
  • arr (ndarray) – Array to quantize, usually an image. Expected to be of shape (H,W) or (H,W,C) with C usually being 1 or 3. This array may be changed in-place.
  • nb_bins (int) – Number of equally-sized bins to quantize into. This corresponds to the maximum number of colors in an output image.
  • to_bin_centers (bool) – Whether to quantize each bin (a, b) to a + (b-a)/2 (center of bin, True) or to a (lower boundary, False).
Returns:

Array with quantized components. This may be the input array with components changed in-place.

Return type:

ndarray

Examples

>>> import imgaug.augmenters as iaa
>>> import numpy as np
>>> image = np.arange(4 * 4 * 3, dtype=np.uint8).reshape((4, 4, 3))
>>> image_quantized = iaa.quantize_uniform_(np.copy(image), 6)

Generates a 4x4 image with 3 channels, containing consecutive values from 0 to 4*4*3, leading to an equal number of colors. Each component is then quantized into one of 6 bins that regularly split up the value range of [0..255], i.e. the resolution w.r.t. to the value range is reduced.

imgaug.augmenters.color.quantize_uniform_to_n_bits(arr, nb_bits)[source]

Reduce each component in an array to a maximum number of bits.

See quantize_uniform_to_n_bits() for details.

Added in 0.4.0.

Supported dtypes:

See quantize_uniform_to_n_bits_().

Parameters:
Returns:

Array with quantized components.

Return type:

ndarray

imgaug.augmenters.color.quantize_uniform_to_n_bits_(arr, nb_bits)[source]

Reduce each component in an array to a maximum number of bits in-place.

This operation sets the 8-B highest frequency (rightmost) bits to zero. For B bits this is equivalent to changing each component’s intensity value v to v' = v & (2**(8-B) - 1), e.g. for B=3 this results in v' = c & ~(2**(3-1) - 1) = c & ~3 = c & ~0000 0011 = c & 1111 1100.

This is identical to quantize_uniform() with nb_bins=2**nb_bits and to_bin_centers=False.

This function produces the same outputs as PIL.ImageOps.posterize(), but is significantly faster.

Added in 0.4.0.

Supported dtypes:

See quantize_uniform_().

Parameters:
  • arr (ndarray) – Array to quantize, usually an image. Expected to be of shape (H,W) or (H,W,C) with C usually being 1 or 3. This array may be changed in-place.
  • nb_bits (int) – Number of bits to keep in each array component.
Returns:

Array with quantized components. This may be the input array with components changed in-place.

Return type:

ndarray

Examples

>>> import imgaug.augmenters as iaa
>>> import numpy as np
>>> image = np.arange(4 * 4 * 3, dtype=np.uint8).reshape((4, 4, 3))
>>> image_quantized = iaa.quantize_uniform_to_n_bits_(np.copy(image), 6)

Generates a 4x4 image with 3 channels, containing consecutive values from 0 to 4*4*3, leading to an equal number of colors. These colors are then quantized so that each component’s 8-6=2 rightmost bits are set to zero.