imgaug.augmenters.edges

Augmenters that deal with edge detection.

List of augmenters:

EdgeDetect and DirectedEdgeDetect are currently still in convolutional.py.

class imgaug.augmenters.edges.Canny(alpha=(0.0, 1.0), hysteresis_thresholds=((60, 140), (160, 240)), sobel_kernel_size=(3, 7), colorizer=None, seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.meta.Augmenter

Apply a canny edge detector to input images.

Supported dtypes:

  • uint8: yes; fully tested
  • uint16: no; not tested
  • uint32: no; not tested
  • uint64: no; not tested
  • int8: no; not tested
  • int16: no; not tested
  • int32: no; not tested
  • int64: no; not tested
  • float16: no; not tested
  • float32: no; not tested
  • float64: no; not tested
  • float128: no; not tested
  • bool: no; not tested
Parameters:
  • alpha (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – Blending factor to use in alpha blending. A value close to 1.0 means that only the edge image is visible. A value close to 0.0 means that only the original image is visible. A value close to 0.5 means that the images are merged according to 0.5*image + 0.5*edge_image. If a sample from this parameter is 0, no action will be performed for the corresponding image.

    • 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.
  • hysteresis_thresholds (number or tuple of number or list of number or imgaug.parameters.StochasticParameter or tuple of tuple of number or tuple of list of number or tuple of imgaug.parameters.StochasticParameter, optional) – Min and max values to use in hysteresis thresholding. (This parameter seems to have not very much effect on the results.) Either a single parameter or a tuple of two parameters. If a single parameter is provided, the sampling happens once for all images with (N,2) samples being requested from the parameter, where each first value denotes the hysteresis minimum and each second the maximum. If a tuple of two parameters is provided, one sampling of (N,) values is independently performed per parameter (first parameter: hysteresis minimum, second: hysteresis maximum).

    • If this is a single number, both min and max value will always be exactly that value.
    • If this is a tuple of numbers (a, b), two random values from the range a <= x <= b will be sampled per image.
    • If this is a list, two random values will be sampled from that list per image.
    • If this is a StochasticParameter, two random values will be sampled from that parameter per image.
    • If this is a tuple (min, max) with min and max both not being numbers, they will be treated according to the rules above (i.e. may be a number, tuple, list or StochasticParameter). A single value will be sampled per image and parameter.
  • sobel_kernel_size (int or tuple of int or list of int or imgaug.parameters.StochasticParameter, optional) – Kernel size of the sobel operator initially applied to each image. This corresponds to apertureSize in cv2.Canny(). If a sample from this parameter is <=1, no action will be performed for the corresponding image. The maximum for this parameter is 7 (inclusive). Higher values are not accepted by OpenCV. If an even value v is sampled, it is automatically changed to v-1.

    • If this is a single integer, the kernel size always matches that value.
    • If this is a tuple of integers (a, b), a random discrete value will be sampled from the range a <= x <= b per image.
    • If this is a list, a random value will be sampled from that list per image.
    • If this is a StochasticParameter, a random value will be sampled from that parameter per image.
  • colorizer (None or imgaug.augmenters.edges.IBinaryImageColorizer, optional) – A strategy to convert binary edge images to color images. If this is None, an instance of RandomColorBinaryImageColorizer is created, which means that each edge image is converted into an uint8 image, where edge and non-edge pixels each have a different color that was uniformly randomly sampled from the space of all uint8 colors.

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

Create an augmenter that generates random blends between images and their canny edge representations.

>>> aug = iaa.Canny(alpha=(0.0, 0.5))

Create a canny edge augmenter that generates edge images with a blending factor of max 50%, i.e. the original (non-edge) image is always at least partially visible.

>>> aug = iaa.Canny(
>>>     alpha=(0.0, 0.5),
>>>     colorizer=iaa.RandomColorsBinaryImageColorizer(
>>>         color_true=255,
>>>         color_false=0
>>>     )
>>> )

Same as in the previous example, but the edge image always uses the color white for edges and black for the background.

>>> aug = iaa.Canny(alpha=(0.5, 1.0), sobel_kernel_size=[3, 7])

Create a canny edge augmenter that initially preprocesses images using a sobel filter with kernel size of either 3x3 or 13x13 and alpha-blends with result using a strength of 50% (both images equally visible) to 100% (only edge image visible).

>>> aug = iaa.Alpha(
>>>     (0.0, 1.0),
>>>     iaa.Canny(alpha=1),
>>>     iaa.MedianBlur(13)
>>> )

Create an augmenter that blends a canny edge image with a median-blurred version of the input image. The median blur uses a fixed kernel size of 13x13 pixels.

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.edges.IBinaryImageColorizer[source]

Bases: object

Interface for classes that convert binary masks to color images.

Methods

colorize(self, image_binary, image_original, …) Convert a binary image to a colorized one.
colorize(self, image_binary, image_original, nth_image, random_state)[source]

Convert a binary image to a colorized one.

Parameters:
  • image_binary (ndarray) – Boolean (H,W) image.
  • image_original (ndarray) – Original (H,W,C) input image.
  • nth_image (int) – Index of the image in the batch.
  • random_state (imgaug.random.RNG) – Random state to use.
Returns:

Colorized form of image_binary.

Return type:

ndarray

class imgaug.augmenters.edges.RandomColorsBinaryImageColorizer(color_true=(0, 255), color_false=(0, 255))[source]

Bases: imgaug.augmenters.edges.IBinaryImageColorizer

Colorizer using two randomly sampled foreground/background colors.

Parameters:
  • color_true (int or tuple of int or list of int or imgaug.parameters.StochasticParameter, optional) – Color of the foreground, i.e. all pixels in binary images that are True. This parameter will be queried once per image to generate (3,) samples denoting the color. (Note that even for grayscale images three values will be sampled and converted to grayscale according to 0.299*R + 0.587*G + 0.114*B. This is the same equation that is also used by OpenCV.)

    • If an int, exactly that value will always be used, i.e. every color will be (v, v, v) for value v.
    • If a tuple (a, b), three random values from the range a <= x <= b will be sampled per image.
    • If a list, then three random values will be sampled from that list per image.
    • If a StochasticParameter, three values will be sampled from the parameter per image.
  • color_false (int or tuple of int or list of int or imgaug.parameters.StochasticParameter, optional) – Analogous to color_true, but denotes the color for all pixels that are False in the binary input image.

Methods

colorize(self, image_binary, image_original, …) Convert a binary image to a colorized one.
colorize(self, image_binary, image_original, nth_image, random_state)[source]

Convert a binary image to a colorized one.

Parameters:
  • image_binary (ndarray) – Boolean (H,W) image.
  • image_original (ndarray) – Original (H,W,C) input image.
  • nth_image (int) – Index of the image in the batch.
  • random_state (imgaug.random.RNG) – Random state to use.
Returns:

Colorized form of image_binary.

Return type:

ndarray