imgaug.augmenters.color

Augmenters that affect image colors or image colorspaces.

Do not import directly from this file, as the categorization is not final. Use instead

from imgaug import augmenters as iaa

and then e.g.

seq = iaa.Sequential([
    iaa.Grayscale((0.0, 1.0)),
    iaa.AddToHueAndSaturation((-10, 10))
])

List of augmenters:

  • InColorspace (deprecated)
  • WithColorspace
  • WithHueAndSaturation
  • MultiplyHueAndSaturation
  • MultiplyHue
  • MultiplySaturation
  • AddToHueAndSaturation
  • AddToHue
  • AddToSaturation
  • ChangeColorspace
  • Grayscale
  • KMeansColorQuantization
  • UniformColorQuantization
class imgaug.augmenters.color.AddToHue(value=(-255, 255), from_colorspace='RGB', name=None, deterministic=False, random_state=None)[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=...).

dtype support:

See `imgaug.augmenters.color.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 imgaug.augmenters.color.change_colorspace_().

  • name (None or str, optional) – See imgaug.augmenters.meta.Augmenter.__init__().

  • deterministic (bool, optional) – See imgaug.augmenters.meta.Augmenter.__init__().

  • random_state (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.bit_generator.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – See imgaug.augmenters.meta.Augmenter.__init__().

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 imgaug.augmenters.meta.Augmenter.augment().
augment(self[, return_batch, hooks]) Augment a batch.
augment_batch(self, batch[, hooks]) Augment a single batch.
augment_batches(self, batches[, hooks, …]) Augment multiple batches.
augment_bounding_boxes(self, …[, hooks]) 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.
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_inplace(self, func[, parents]) Remove in-place children of this augmenter that match a condition.
reseed(self[, random_state, deterministic_too]) Reseed 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  
class imgaug.augmenters.color.AddToHueAndSaturation(value=None, value_hue=None, value_saturation=None, per_channel=False, from_colorspace='RGB', name=None, deterministic=False, random_state=None)[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

dtype support:

See :func:`imgaug.augmenters.color.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 imgaug.augmenters.color.change_colorspace_().

  • name (None or str, optional) – See imgaug.augmenters.meta.Augmenter.__init__().

  • deterministic (bool, optional) – See imgaug.augmenters.meta.Augmenter.__init__().

  • random_state (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.bit_generator.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – See imgaug.augmenters.meta.Augmenter.__init__().

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 imgaug.augmenters.meta.Augmenter.augment().
augment(self[, return_batch, hooks]) Augment a batch.
augment_batch(self, batch[, hooks]) Augment a single batch.
augment_batches(self, batches[, hooks, …]) Augment multiple batches.
augment_bounding_boxes(self, …[, hooks]) 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.
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_inplace(self, func[, parents]) Remove in-place children of this augmenter that match a condition.
reseed(self[, random_state, deterministic_too]) Reseed 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  
get_parameters(self)[source]
class imgaug.augmenters.color.AddToSaturation(value=(-75, 75), from_colorspace='RGB', name=None, deterministic=False, random_state=None)[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=...).

dtype support:

See `imgaug.augmenters.color.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 imgaug.augmenters.color.change_colorspace_().

  • name (None or str, optional) – See imgaug.augmenters.meta.Augmenter.__init__().

  • deterministic (bool, optional) – See imgaug.augmenters.meta.Augmenter.__init__().

  • random_state (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.bit_generator.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – See imgaug.augmenters.meta.Augmenter.__init__().

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 imgaug.augmenters.meta.Augmenter.augment().
augment(self[, return_batch, hooks]) Augment a batch.
augment_batch(self, batch[, hooks]) Augment a single batch.
augment_batches(self, batches[, hooks, …]) Augment multiple batches.
augment_bounding_boxes(self, …[, hooks]) 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.
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_inplace(self, func[, parents]) Remove in-place children of this augmenter that match a condition.
reseed(self[, random_state, deterministic_too]) Reseed 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  
class imgaug.augmenters.color.ChangeColorspace(to_colorspace, from_colorspace='RGB', alpha=1.0, name=None, deterministic=False, random_state=None)[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.

dtype support:

See :func:`imgaug.augmenters.color.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.
  • name (None or str, optional) – See imgaug.augmenters.meta.Augmenter.__init__().

  • deterministic (bool, optional) – See imgaug.augmenters.meta.Augmenter.__init__().

  • random_state (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.bit_generator.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – See imgaug.augmenters.meta.Augmenter.__init__().

Methods

__call__(self, \*args, \*\*kwargs) Alias for imgaug.augmenters.meta.Augmenter.augment().
augment(self[, return_batch, hooks]) Augment a batch.
augment_batch(self, batch[, hooks]) Augment a single batch.
augment_batches(self, batches[, hooks, …]) Augment multiple batches.
augment_bounding_boxes(self, …[, hooks]) 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.
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_inplace(self, func[, parents]) Remove in-place children of this augmenter that match a condition.
reseed(self[, random_state, deterministic_too]) Reseed 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  
BGR = 'BGR'
CIE = 'CIE'
COLORSPACES = {'BGR', 'CIE', 'GRAY', 'HLS', 'HSV', 'Lab', 'Luv', 'RGB', 'YCrCb'}
CV_VARS = {'BGR2CIE': <MagicMock id='140606031721080'>, 'BGR2GRAY': <MagicMock id='140606031790488'>, 'BGR2HLS': <MagicMock id='140606031770904'>, 'BGR2HSV': <MagicMock id='140606031746104'>, 'BGR2Lab': <MagicMock id='140606031832568'>, 'BGR2Luv': <MagicMock id='140606031804120'>, 'BGR2RGB': <MagicMock id='140606030655672'>, 'BGR2YCrCb': <MagicMock id='140606031725400'>, 'HLS2BGR': <MagicMock id='140606031845976'>, 'HLS2RGB': <MagicMock id='140606031866232'>, 'HSV2BGR': <MagicMock id='140606031816856'>, 'HSV2RGB': <MagicMock id='140606031800248'>, 'Lab2BGR': <MagicMock id='140606031916504'>, 'Lab2RGB': <MagicMock id='140606031911960'>, 'RGB2BGR': <MagicMock id='140606030522744'>, 'RGB2CIE': <MagicMock id='140606030490424'>, 'RGB2GRAY': <MagicMock id='140606029425240'>, 'RGB2HLS': <MagicMock id='140606030609880'>, 'RGB2HSV': <MagicMock id='140606030605560'>, 'RGB2Lab': <MagicMock id='140606030622392'>, 'RGB2Luv': <MagicMock id='140606030639000'>, 'RGB2YCrCb': <MagicMock id='140606030572568'>}
GRAY = 'GRAY'
HLS = 'HLS'
HSV = 'HSV'
Lab = 'Lab'
Luv = 'Luv'
RGB = 'RGB'
YCrCb = 'YCrCb'
get_parameters(self)[source]
class imgaug.augmenters.color.Grayscale(alpha=0, from_colorspace='RGB', name=None, deterministic=False, random_state=None)[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

dtype support:

See :func:`imgaug.augmenters.color.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). Allowed strings are: RGB, BGR, GRAY, CIE, YCrCb, HSV, HLS, Lab, Luv. See imgaug.augmenters.color.change_colorspace_().

  • name (None or str, optional) – See imgaug.augmenters.meta.Augmenter.__init__().

  • deterministic (bool, optional) – See imgaug.augmenters.meta.Augmenter.__init__().

  • random_state (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.bit_generator.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – See imgaug.augmenters.meta.Augmenter.__init__().

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 imgaug.augmenters.meta.Augmenter.augment().
augment(self[, return_batch, hooks]) Augment a batch.
augment_batch(self, batch[, hooks]) Augment a single batch.
augment_batches(self, batches[, hooks, …]) Augment multiple batches.
augment_bounding_boxes(self, …[, hooks]) 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.
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_inplace(self, func[, parents]) Remove in-place children of this augmenter that match a condition.
reseed(self[, random_state, deterministic_too]) Reseed 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  
imgaug.augmenters.color.InColorspace(to_colorspace, from_colorspace='RGB', children=None, name=None, deterministic=False, random_state=None)[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', name=None, deterministic=False, random_state=None)[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.

dtype support:

if (image size <= max_size)::

    minimum of (
        ``imgaug.augmenters.color.ChangeColorspace``,
        :func:`imgaug.augmenters.color.quantize_colors_kmeans`
    )

if (image size > max_size)::

    minimum of (
        ``imgaug.augmenters.color.ChangeColorspace``,
        :func:`imgaug.augmenters.color.quantize_colors_kmeans`,
        :func:`imgaug.imgaug.imresize_single_image`
    )
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 imgaug.augmenters.color.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 imgaug.imgaug.imresize_single_image().

  • name (None or str, optional) – See imgaug.augmenters.meta.Augmenter.__init__().

  • deterministic (bool, optional) – See imgaug.augmenters.meta.Augmenter.__init__().

  • random_state (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.bit_generator.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – See imgaug.augmenters.meta.Augmenter.__init__().

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.

Methods

__call__(self, \*args, \*\*kwargs) Alias for imgaug.augmenters.meta.Augmenter.augment().
augment(self[, return_batch, hooks]) Augment a batch.
augment_batch(self, batch[, hooks]) Augment a single batch.
augment_batches(self, batches[, hooks, …]) Augment multiple batches.
augment_bounding_boxes(self, …[, hooks]) 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.
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_inplace(self, func[, parents]) Remove in-place children of this augmenter that match a condition.
reseed(self[, random_state, deterministic_too]) Reseed 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  
class imgaug.augmenters.color.MultiplyHue(mul=(-1.0, 1.0), from_colorspace='RGB', name=None, deterministic=False, random_state=None)[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=...).

dtype support:

See `imgaug.augmenters.color.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 imgaug.augmenters.color.change_colorspace_().

  • name (None or str, optional) – See imgaug.augmenters.meta.Augmenter.__init__().

  • deterministic (bool, optional) – See imgaug.augmenters.meta.Augmenter.__init__().

  • random_state (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.bit_generator.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – See imgaug.augmenters.meta.Augmenter.__init__().

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 imgaug.augmenters.meta.Augmenter.augment().
augment(self[, return_batch, hooks]) Augment a batch.
augment_batch(self, batch[, hooks]) Augment a single batch.
augment_batches(self, batches[, hooks, …]) Augment multiple batches.
augment_bounding_boxes(self, …[, hooks]) 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.
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_inplace(self, func[, parents]) Remove in-place children of this augmenter that match a condition.
reseed(self[, random_state, deterministic_too]) Reseed 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  
class imgaug.augmenters.color.MultiplyHueAndSaturation(mul=None, mul_hue=None, mul_saturation=None, per_channel=False, from_colorspace='RGB', name=None, deterministic=False, random_state=None)[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.

dtype support:

See `imgaug.augmenters.color.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 imgaug.augmenters.color.change_colorspace_().

  • name (None or str, optional) – See imgaug.augmenters.meta.Augmenter.__init__().

  • deterministic (bool, optional) – See imgaug.augmenters.meta.Augmenter.__init__().

  • random_state (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.bit_generator.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – See imgaug.augmenters.meta.Augmenter.__init__().

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 imgaug.augmenters.meta.Augmenter.augment().
augment(self[, return_batch, hooks]) Augment a batch.
augment_batch(self, batch[, hooks]) Augment a single batch.
augment_batches(self, batches[, hooks, …]) Augment multiple batches.
augment_bounding_boxes(self, …[, hooks]) 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.
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_inplace(self, func[, parents]) Remove in-place children of this augmenter that match a condition.
reseed(self[, random_state, deterministic_too]) Reseed 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  
class imgaug.augmenters.color.MultiplySaturation(mul=(0.0, 3.0), from_colorspace='RGB', name=None, deterministic=False, random_state=None)[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=...).

dtype support:

See `imgaug.augmenters.color.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 imgaug.augmenters.color.change_colorspace_().

  • name (None or str, optional) – See imgaug.augmenters.meta.Augmenter.__init__().

  • deterministic (bool, optional) – See imgaug.augmenters.meta.Augmenter.__init__().

  • random_state (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.bit_generator.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – See imgaug.augmenters.meta.Augmenter.__init__().

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 imgaug.augmenters.meta.Augmenter.augment().
augment(self[, return_batch, hooks]) Augment a batch.
augment_batch(self, batch[, hooks]) Augment a single batch.
augment_batches(self, batches[, hooks, …]) Augment multiple batches.
augment_bounding_boxes(self, …[, hooks]) 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.
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_inplace(self, func[, parents]) Remove in-place children of this augmenter that match a condition.
reseed(self[, random_state, deterministic_too]) Reseed 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  
class imgaug.augmenters.color.UniformColorQuantization(n_colors=(2, 16), from_colorspace='RGB', to_colorspace=None, max_size=None, interpolation='linear', name=None, deterministic=False, random_state=None)[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.

dtype support:

if (image size <= max_size)::

    minimum of (
        ``imgaug.augmenters.color.ChangeColorspace``,
        :func:`imgaug.augmenters.color.quantize_colors_uniform`
    )

if (image size > max_size)::

    minimum of (
        ``imgaug.augmenters.color.ChangeColorspace``,
        :func:`imgaug.augmenters.color.quantize_colors_uniform`,
        :func:`imgaug.imgaug.imresize_single_image`
    )
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 imgaug.augmenters.color.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 imgaug.imgaug.imresize_single_image().

  • name (None or str, optional) – See imgaug.augmenters.meta.Augmenter.__init__().

  • deterministic (bool, optional) – See imgaug.augmenters.meta.Augmenter.__init__().

  • random_state (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.bit_generator.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – See imgaug.augmenters.meta.Augmenter.__init__().

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.

Methods

__call__(self, \*args, \*\*kwargs) Alias for imgaug.augmenters.meta.Augmenter.augment().
augment(self[, return_batch, hooks]) Augment a batch.
augment_batch(self, batch[, hooks]) Augment a single batch.
augment_batches(self, batches[, hooks, …]) Augment multiple batches.
augment_bounding_boxes(self, …[, hooks]) 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.
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_inplace(self, func[, parents]) Remove in-place children of this augmenter that match a condition.
reseed(self[, random_state, deterministic_too]) Reseed 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  
class imgaug.augmenters.color.WithColorspace(to_colorspace, from_colorspace='RGB', children=None, name=None, deterministic=False, random_state=None)[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.

dtype support:

See :func:`imgaug.augmenters.color.change_colorspaces_`.
Parameters:
  • to_colorspace (str) – See imgaug.augmenters.color.change_colorspace_().
  • from_colorspace (str, optional) – See imgaug.augmenters.color.change_colorspace_().
  • children (None or Augmenter or list of Augmenters, optional) – See imgaug.augmenters.ChangeColorspace.__init__().
  • name (None or str, optional) – See imgaug.augmenters.meta.Augmenter.__init__().
  • deterministic (bool, optional) – See imgaug.augmenters.meta.Augmenter.__init__().
  • random_state (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.bit_generator.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – See imgaug.augmenters.meta.Augmenter.__init__().

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 imgaug.augmenters.meta.Augmenter.augment().
augment(self[, return_batch, hooks]) Augment a batch.
augment_batch(self, batch[, hooks]) Augment a single batch.
augment_batches(self, batches[, hooks, …]) Augment multiple batches.
augment_bounding_boxes(self, …[, hooks]) 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.
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_inplace(self, func[, parents]) Remove in-place children of this augmenter that match a condition.
reseed(self[, random_state, deterministic_too]) Reseed 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  
get_children_lists(self)[source]

Get a list of lists of children of this augmenter.

For most augmenters, the result will be a single empty list. For augmenters with children it will often be a list with one sublist containing all children. In some cases the augmenter will contain multiple distinct lists of children, e.g. an if-list and an else-list. This will lead to a result consisting of a single list with multiple sublists, each representing the respective sublist of children.

E.g. for an if/else-augmenter that executes the children A1, A2 if a condition is met and otherwise executes the children B1, B2, B3 the result will be [[A1, A2], [B1, B2, B3]].

IMPORTANT: While the topmost list may be newly created, each of the sublist must be editable inplace resulting in a changed children list of the augmenter. E.g. if an Augmenter IfElse(condition, [A1, A2], [B1, B2, B3]) returns [[A1, A2], [B1, B2, B3]] for a call to imgaug.augmenters.meta.Augmenter.get_children_lists() and A2 is removed inplace from [A1, A2], then the children lists of IfElse(...) must also change to [A1], [B1, B2, B3]. This is used in imgaug.augmeneters.meta.Augmenter.remove_augmenters_inplace().

Returns:One or more lists of child augmenter. Can also be a single empty list.
Return type:list of list of imgaug.augmenters.meta.Augmenter
get_parameters(self)[source]
class imgaug.augmenters.color.WithHueAndSaturation(children=None, from_colorspace='RGB', name=None, deterministic=False, random_state=None)[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).

dtype support:

See :func:`imgaug.augmenters.color.change_colorspaces_`.
Parameters:
  • from_colorspace (str, optional) – See imgaug.augmenters.color.change_colorspace_().
  • children (None or Augmenter or list of Augmenters, optional) – See imgaug.augmenters.ChangeColorspace.__init__().
  • name (None or str, optional) – See imgaug.augmenters.meta.Augmenter.__init__().
  • deterministic (bool, optional) – See imgaug.augmenters.meta.Augmenter.__init__().
  • random_state (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.bit_generator.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – See imgaug.augmenters.meta.Augmenter.__init__().

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 imgaug.augmenters.meta.Augmenter.augment().
augment(self[, return_batch, hooks]) Augment a batch.
augment_batch(self, batch[, hooks]) Augment a single batch.
augment_batches(self, batches[, hooks, …]) Augment multiple batches.
augment_bounding_boxes(self, …[, hooks]) 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.
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_inplace(self, func[, parents]) Remove in-place children of this augmenter that match a condition.
reseed(self[, random_state, deterministic_too]) Reseed 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  
get_children_lists(self)[source]

Get a list of lists of children of this augmenter.

For most augmenters, the result will be a single empty list. For augmenters with children it will often be a list with one sublist containing all children. In some cases the augmenter will contain multiple distinct lists of children, e.g. an if-list and an else-list. This will lead to a result consisting of a single list with multiple sublists, each representing the respective sublist of children.

E.g. for an if/else-augmenter that executes the children A1, A2 if a condition is met and otherwise executes the children B1, B2, B3 the result will be [[A1, A2], [B1, B2, B3]].

IMPORTANT: While the topmost list may be newly created, each of the sublist must be editable inplace resulting in a changed children list of the augmenter. E.g. if an Augmenter IfElse(condition, [A1, A2], [B1, B2, B3]) returns [[A1, A2], [B1, B2, B3]] for a call to imgaug.augmenters.meta.Augmenter.get_children_lists() and A2 is removed inplace from [A1, A2], then the children lists of IfElse(...) must also change to [A1], [B1, B2, B3]. This is used in imgaug.augmeneters.meta.Augmenter.remove_augmenters_inplace().

Returns:One or more lists of child augmenter. Can also be a single empty list.
Return type:list of list of imgaug.augmenters.meta.Augmenter
get_parameters(self)[source]
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.

dtype support:

* ``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.

dtype support:

See :func:`imgaug.augmenters.color.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 list of str) – The target colorspaces. Either a single string (all images will be converted to the same colorspace) or a list 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.quantize_colors_kmeans(image, n_colors, n_max_iter=10, eps=1.0)[source]

Apply k-Means color quantization to an image.

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

dtype support:

* ``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) – Image in which to quantize colors. Expected to be of shape (H,W) or (H,W,C) with C usually being 1 or 3.
  • n_colors (int) – Maximum number of output colors.
  • n_max_iter (int, optional) – Maximum number of iterations in k-Means.
  • 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_colors_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_colors_uniform(image, n_colors)[source]

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.

dtype support:

* ``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) – Image in which to quantize colors. Expected to be of shape (H,W) or (H,W,C) with C usually being 1 or 3.
  • n_colors (int) – Maximum number of output colors.
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_colors_uniform(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.