Replace image with superpixel segmentation (SLIC). p_replace, n_segments, max_size control fraction and segment count. Reduces fine texture.
p_replaceDefines for any segment the probability that the pixels within that segment are replaced by their average color (otherwise, the pixels are not changed).
0.0 would mean, that the pixels in no
segment are replaced by their average color (image is not
changed at all).0.5 would mean, that around half of all
segments are replaced by their average color.1.0 would mean, that all segments are
replaced by their average color (resulting in a voronoi
image).Behavior based on chosen data types for this parameter:
float, then that float will always be used.tuple (a, b), then a random probability will be
sampled from the interval [a, b] per image.
Default: (0.1, 0.3)n_segmentsRough target number of how many superpixels to generate.
The algorithm may deviate from this number.
Lower value will lead to coarser superpixels.
Higher values are computationally more intensive and will hence lead to a slowdown.
If tuple (a, b), then a value from the discrete interval [a..b] will be sampled per image.
Default: (15, 120)
max_sizeMaximum image size at which the augmentation is performed.
If the width or height of an image exceeds this value, it will be
downscaled before the augmentation so that the longest side matches max_size.
This is done to speed up the process. The final output image has the same size as the input image.
Note that in case p_replace is below 1.0,
the down-/upscaling will affect the not-replaced pixels too.
Use None to apply no down-/upscaling.
Default: 128
interpolationFlag that is used to specify the interpolation algorithm. Should be one of: cv2.INTER_NEAREST, cv2.INTER_LINEAR, cv2.INTER_CUBIC, cv2.INTER_AREA, cv2.INTER_LANCZOS4. Default: cv2.INTER_LINEAR.
pProbability of applying the transform. Default: 0.5.
>>> import numpy as np
>>> import albumentations as A
>>> image = np.random.randint(0, 256, (100, 100, 3), dtype=np.uint8)
# Apply superpixels with default parameters
>>> transform = A.Superpixels(p=1.0)
>>> augmented_image = transform(image=image)['image']
# Apply superpixels with custom parameters
>>> transform = A.Superpixels(
... p_replace=(0.5, 0.7),
... n_segments=(50, 100),
... max_size=None,
... interpolation=cv2.INTER_NEAREST,
... p=1.0
... )
>>> augmented_image = transform(image=image)['image']max_size to limit the image size.p_replace and n_segments parameters.p_replace is high, the image can become highly abstracted, resembling a voronoi diagram.