imgaug.augmenters.artistic

Augmenters that apply artistic image filters.

List of augmenters:

Added in 0.4.0.

class imgaug.augmenters.artistic.Cartoon(blur_ksize=(1, 5), segmentation_size=(0.8, 1.2), saturation=(1.5, 2.5), edge_prevalence=(0.9, 1.1), from_colorspace='RGB', seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.meta.Augmenter

Convert the style of images to a more cartoonish one.

This augmenter was primarily designed for images with a size of 200 to 800 pixels. Smaller or larger images may cause issues.

Note that the quality of the results can currently not compete with learned style transfer, let alone human-made images. A lack of detected edges or also too many detected edges are probably the most significant drawbacks.

Added in 0.4.0.

Supported dtypes:

See stylize_cartoon().

Parameters:
  • blur_ksize (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – Median filter kernel size. See stylize_cartoon() for details.

    • If number: That value will be used for all images.
    • If tuple (a, b) of number: A random value will be uniformly sampled per image from the interval [a, b).
    • If list: A random value will be picked per image from the list.
    • If StochasticParameter: The parameter will be queried once per batch for (N,) values, where N is the number of images.
  • segmentation_size (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – Mean-Shift segmentation size multiplier. See stylize_cartoon() for details.

    • If number: That value will be used for all images.
    • If tuple (a, b) of number: A random value will be uniformly sampled per image from the interval [a, b).
    • If list: A random value will be picked per image from the list.
    • If StochasticParameter: The parameter will be queried once per batch for (N,) values, where N is the number of images.
  • saturation (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – Saturation multiplier. See stylize_cartoon() for details.

    • If number: That value will be used for all images.
    • If tuple (a, b) of number: A random value will be uniformly sampled per image from the interval [a, b).
    • If list: A random value will be picked per image from the list.
    • If StochasticParameter: The parameter will be queried once per batch for (N,) values, where N is the number of images.
  • edge_prevalence (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – Multiplier for the prevalence of edges. See stylize_cartoon() for details.

    • If number: That value will be used for all images.
    • If tuple (a, b) of number: A random value will be uniformly sampled per image from the interval [a, b).
    • If list: A random value will be picked per image from the list.
    • If StochasticParameter: The parameter will be queried once per batch for (N,) values, where N is the number of images.
  • from_colorspace (str, optional) – The source colorspace. Use one of imgaug.augmenters.color.CSPACE_*. Defaults to RGB.

  • 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.Cartoon()

Create an example image, then apply a cartoon filter to it.

>>> aug = iaa.Cartoon(blur_ksize=3, segmentation_size=1.0,
>>>                   saturation=2.0, edge_prevalence=1.0)

Create a non-stochastic cartoon augmenter that produces decent-looking images.

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().

imgaug.augmenters.artistic.stylize_cartoon(image, blur_ksize=3, segmentation_size=1.0, saturation=2.0, edge_prevalence=1.0, suppress_edges=True, from_colorspace='RGB')[source]

Convert the style of an image to a more cartoonish one.

This function was primarily designed for images with a size of 200 to 800 pixels. Smaller or larger images may cause issues.

Note that the quality of the results can currently not compete with learned style transfer, let alone human-made images. A lack of detected edges or also too many detected edges are probably the most significant drawbacks.

This method is loosely based on the one proposed in https://stackoverflow.com/a/11614479/3760780

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:
  • image (ndarray) – A (H,W,3) uint8 image array.
  • blur_ksize (int, optional) – Kernel size of the median blur filter applied initially to the input image. Expected to be an odd value and >=0. If an even value, thn automatically increased to an odd one. If <=1, no blur will be applied.
  • segmentation_size (float, optional) – Size multiplier to decrease/increase the base size of the initial mean-shift segmentation of the image. Expected to be >=0. Note that the base size is increased by roughly a factor of two for images with height and/or width >=400.
  • edge_prevalence (float, optional) – Multiplier for the prevalance of edges. Higher values lead to more edges. Note that the default value of 1.0 is already fairly conservative, so there is limit effect from lowerin it further.
  • saturation (float, optional) – Multiplier for the saturation. Set to 1.0 to not change the image’s saturation.
  • suppress_edges (bool, optional) – Whether to run edge suppression to remove blobs containing too many or too few edge pixels.
  • from_colorspace (str, optional) – The source colorspace. Use one of imgaug.augmenters.color.CSPACE_*. Defaults to RGB.
Returns:

Image in cartoonish style.

Return type:

ndarray