imgaug.augmenters.contrast¶
Augmenters that perform contrast changes.
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.GammaContrast((0.5, 1.5))])
List of augmenters:
- GammaContrast
- SigmoidContrast
- LogContrast
- LinearContrast
- AllChannelsHistogramEqualization
- HistogramEqualization
- AllChannelsCLAHE
- CLAHE
-
class
imgaug.augmenters.contrast.
AllChannelsCLAHE
(clip_limit=40, tile_grid_size_px=8, tile_grid_size_px_min=3, per_channel=False, name=None, deterministic=False, random_state=None)[source]¶ Bases:
imgaug.augmenters.meta.Augmenter
Apply CLAHE to all channels of images in their original colorspaces.
CLAHE (Contrast Limited Adaptive Histogram Equalization) performs histogram equilization within image patches, i.e. over local neighbourhoods.
In contrast to
imgaug.augmenters.contrast.CLAHE
, this augmenter operates directly on all channels of the input images. It does not perform any colorspace transformations and does not focus on specific channels (e.g.L
inLab
colorspace).dtype support:
* ``uint8``: yes; fully tested * ``uint16``: yes; tested * ``uint32``: no (1) * ``uint64``: no (2) * ``int8``: no (2) * ``int16``: no (2) * ``int32``: no (2) * ``int64``: no (2) * ``float16``: no (2) * ``float32``: no (2) * ``float64``: no (2) * ``float128``: no (1) * ``bool``: no (1) - (1) rejected by cv2 - (2) results in error in cv2: ``cv2.error: OpenCV(3.4.2) (...)/clahe.cpp:351: error: (-215:Assertion failed) src.type() == (((0) & ((1 << 3) - 1)) + (((1)-1) << 3)) || _src.type() == (((2) & ((1 << 3) - 1)) + (((1)-1) << 3)) in function 'apply'``
Parameters: - clip_limit (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – See
imgaug.augmenters.contrast.CLAHE
. - tile_grid_size_px (int or tuple of int or list of int or imgaug.parameters.StochasticParameter or tuple of tuple of int or tuple of list of int or tuple of imgaug.parameters.StochasticParameter, optional) – See
imgaug.augmenters.contrast.CLAHE
. - tile_grid_size_px_min (int, optional) – See
imgaug.augmenters.contrast.CLAHE
. - per_channel (bool or float, optional) – Whether to use the same value for all channels (
False
) or to sample a new value for each channel (True
). If this value is a floatp
, then forp
percent of all images per_channel will be treated asTrue
, otherwise asFalse
. - 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.AllChannelsCLAHE()
Create an augmenter that applies CLAHE to all channels of input images.
>>> aug = iaa.AllChannelsCLAHE(clip_limit=(1, 10))
Same as in the previous example, but the clip_limit used by CLAHE is uniformly sampled per image from the interval
[1, 10]
. Some images will therefore have stronger contrast than others (i.e. higher clip limit values).>>> aug = iaa.AllChannelsCLAHE(clip_limit=(1, 10), per_channel=True)
Same as in the previous example, but the clip_limit is sampled per image and channel, leading to different levels of contrast for each 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 - clip_limit (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – See
-
class
imgaug.augmenters.contrast.
AllChannelsHistogramEqualization
(name=None, deterministic=False, random_state=None)[source]¶ Bases:
imgaug.augmenters.meta.Augmenter
Apply Histogram Eq. to all channels of images in their original colorspaces.
In contrast to
imgaug.augmenters.contrast.HistogramEqualization
, this augmenter operates directly on all channels of the input images. It does not perform any colorspace transformations and does not focus on specific channels (e.g.L
inLab
colorspace).dtype support:
* ``uint8``: yes; fully tested * ``uint16``: no (1) * ``uint32``: no (2) * ``uint64``: no (1) * ``int8``: no (1) * ``int16``: no (1) * ``int32``: no (1) * ``int64``: no (1) * ``float16``: no (2) * ``float32``: no (1) * ``float64``: no (1) * ``float128``: no (2) * ``bool``: no (1) - (1) causes cv2 error: ``cv2.error: OpenCV(3.4.5) (...)/histogram.cpp:3345: error: (-215:Assertion failed) src.type() == CV_8UC1 in function 'equalizeHist'`` - (2) rejected by cv2
Parameters: - 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.AllChannelsHistogramEqualization()
Create an augmenter that applies histogram equalization to all channels of input images in the original colorspaces.
>>> aug = iaa.Alpha((0.0, 1.0), iaa.AllChannelsHistogramEqualization())
Same as in the previous example, but alpha-blends the contrast-enhanced augmented images with the original input images using random blend strengths. This leads to random strengths of the contrast adjustment.
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 - name (None or str, optional) – See
-
class
imgaug.augmenters.contrast.
CLAHE
(clip_limit=40, tile_grid_size_px=8, tile_grid_size_px_min=3, from_colorspace='RGB', to_colorspace='Lab', name=None, deterministic=False, random_state=None)[source]¶ Bases:
imgaug.augmenters.meta.Augmenter
Apply CLAHE to L/V/L channels in HLS/HSV/Lab colorspaces.
This augmenter applies CLAHE (Contrast Limited Adaptive Histogram Equalization) to images, a form of histogram equalization that normalizes within local image patches. The augmenter transforms input images to a target colorspace (e.g.
Lab
), extracts an intensity-related channel from the converted images (e.g.L
forLab
), applies CLAHE to the channel and then converts the resulting image back to the original colorspace.Grayscale images (images without channel axis or with only one channel axis) are automatically handled, from_colorspace does not have to be adjusted for them. For images with four channels (e.g.
RGBA
), the fourth channel is ignored in the colorspace conversion (e.g. from anRGBA
image, only theRGB
part is converted, normalized, converted back and concatenated with the inputA
channel). Images with unusual channel numbers (2, 5 or more than 5) are normalized channel-by-channel (same behaviour asAllChannelsCLAHE
, though a warning will be raised).If you want to apply CLAHE to each channel of the original input image’s colorspace (without any colorspace conversion), use
imgaug.augmenters.contrast.AllChannelsCLAHE
instead.dtype support:
* ``uint8``: yes; fully tested * ``uint16``: no (1) * ``uint32``: no (1) * ``uint64``: no (1) * ``int8``: no (1) * ``int16``: no (1) * ``int32``: no (1) * ``int64``: no (1) * ``float16``: no (1) * ``float32``: no (1) * ``float64``: no (1) * ``float128``: no (1) * ``bool``: no (1) - (1) This augmenter uses ChangeColorspace, which is currently limited to ``uint8``.
Parameters: clip_limit (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – Clipping limit. Higher values result in stronger contrast. OpenCV uses a default of
40
, though values around5
seem to already produce decent contrast.- If a number, then that value will be used for all images.
- If a tuple
(a, b)
, then a value from the range[a, b]
will be used 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.
tile_grid_size_px (int or tuple of int or list of int or imgaug.parameters.StochasticParameter or tuple of tuple of int or tuple of list of int or tuple of imgaug.parameters.StochasticParameter, optional) –
Kernel size, i.e. size of each local neighbourhood in pixels.
- If an
int
, then that value will be used for all images for both kernel height and width. - If a tuple
(a, b)
, then a value from the discrete interval[a..b]
will be uniformly sampled per image. - If a list, then a random value will be sampled from that list per image and used for both kernel height and width.
- If a
StochasticParameter
, then a value will be sampled per image from that parameter per image and used for both kernel height and width. - If a tuple of tuple of
int
given as((a, b), (c, d))
, then two values will be sampled independently from the discrete ranges[a..b]
and[c..d]
per image and used as the kernel height and width. - If a tuple of lists of
int
, then two values will be sampled independently per image, one from the first list and one from the second, and used as the kernel height and width. - If a tuple of
StochasticParameter
, then two values will be sampled indepdently per image, one from the first parameter and one from the second, and used as the kernel height and width.
- If an
tile_grid_size_px_min (int, optional) – Minimum kernel size in px, per axis. If the sampling results in a value lower than this minimum, it will be clipped to this value.
from_colorspace ({“RGB”, “BGR”, “HSV”, “HLS”, “Lab”}, optional) – Colorspace of the input images. If any input image has only one or zero channels, this setting will be ignored and it will be assumed that the input is grayscale. If a fourth channel is present in an input image, it will be removed before the colorspace conversion and later re-added. See also
imgaug.augmenters.color.change_colorspace_()
for details.to_colorspace ({“Lab”, “HLS”, “HSV”}, optional) – Colorspace in which to perform CLAHE. For
Lab
, CLAHE will only be applied to the first channel (L
), forHLS
to the second (L
) and forHSV
to the third (V
). To apply CLAHE to all channels of an input image (without colorspace conversion), seeimgaug.augmenters.contrast.AllChannelsCLAHE
.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.CLAHE()
Create a standard CLAHE augmenter.
>>> aug = iaa.CLAHE(clip_limit=(1, 10))
Create a CLAHE augmenter with a clip limit uniformly sampled from
[1..10]
, where1
is rather low contrast and10
is rather high contrast.>>> aug = iaa.CLAHE(tile_grid_size_px=(3, 21))
Create a CLAHE augmenter with kernel sizes of
SxS
, whereS
is uniformly sampled from[3..21]
. Sampling happens once per image.>>> aug = iaa.CLAHE( >>> tile_grid_size_px=iap.Discretize(iap.Normal(loc=7, scale=2)), >>> tile_grid_size_px_min=3)
Create a CLAHE augmenter with kernel sizes of
SxS
, whereS
is sampled fromN(7, 2)
, but does not go below3
.>>> aug = iaa.CLAHE(tile_grid_size_px=((3, 21), [3, 5, 7]))
Create a CLAHE augmenter with kernel sizes of
HxW
, whereH
is uniformly sampled from[3..21]
andW
is randomly picked from the list[3, 5, 7]
.>>> aug = iaa.CLAHE( >>> from_colorspace=iaa.CSPACE_BGR, >>> to_colorspace=iaa.CSPACE_HSV)
Create a CLAHE augmenter that converts images from BGR colorspace to HSV colorspace and then applies the local histogram equalization to the
V
channel of the images (before converting back toBGR
). Alternatively,Lab
(default) orHLS
can be used as the target colorspace. Grayscale images (no channels / one channel) are never converted and are instead directly normalized (i.e. from_colorspace does not have to be changed for them).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'¶
-
HLS
= 'HLS'¶
-
HSV
= 'HSV'¶
-
Lab
= 'Lab'¶
-
RGB
= 'RGB'¶
-
class
imgaug.augmenters.contrast.
GammaContrast
(gamma=1, per_channel=False, name=None, deterministic=False, random_state=None)[source]¶ Bases:
imgaug.augmenters.contrast._ContrastFuncWrapper
Adjust image contrast by scaling pixel values to
255*((v/255)**gamma)
.Values in the range
gamma=(0.5, 2.0)
seem to be sensible.dtype support:
See :func:`imgaug.augmenters.contrast.adjust_contrast_gamma`.
Parameters: gamma (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) –
Exponent for the contrast adjustment. Higher values darken the image.
- If a number, then that value will be used for all images.
- If a tuple
(a, b)
, then a value from the range[a, b]
will be used 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.
per_channel (bool or float, optional) – Whether to use the same value for all channels (
False
) or to sample a new value for each channel (True
). If this value is a floatp
, then forp
percent of all images per_channel will be treated asTrue
, otherwise asFalse
.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.GammaContrast((0.5, 2.0))
Modify the contrast of images according to
255*((v/255)**gamma)
, wherev
is a pixel value andgamma
is sampled uniformly from the interval[0.5, 2.0]
(once per image).>>> aug = iaa.GammaContrast((0.5, 2.0), per_channel=True)
Same as in the previous example, but
gamma
is sampled once per image and 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
-
class
imgaug.augmenters.contrast.
HistogramEqualization
(from_colorspace='RGB', to_colorspace='Lab', name=None, deterministic=False, random_state=None)[source]¶ Bases:
imgaug.augmenters.meta.Augmenter
Apply Histogram Eq. to L/V/L channels of images in HLS/HSV/Lab colorspaces.
This augmenter is similar to
imgaug.augmenters.contrast.CLAHE
.The augmenter transforms input images to a target colorspace (e.g.
Lab
), extracts an intensity-related channel from the converted images (e.g.L
forLab
), applies Histogram Equalization to the channel and then converts the resulting image back to the original colorspace.Grayscale images (images without channel axis or with only one channel axis) are automatically handled, from_colorspace does not have to be adjusted for them. For images with four channels (e.g. RGBA), the fourth channel is ignored in the colorspace conversion (e.g. from an
RGBA
image, only theRGB
part is converted, normalized, converted back and concatenated with the inputA
channel). Images with unusual channel numbers (2, 5 or more than 5) are normalized channel-by-channel (same behaviour asAllChannelsHistogramEqualization
, though a warning will be raised).If you want to apply HistogramEqualization to each channel of the original input image’s colorspace (without any colorspace conversion), use
imgaug.augmenters.contrast.AllChannelsHistogramEqualization
instead.dtype support:
* ``uint8``: yes; fully tested * ``uint16``: no (1) * ``uint32``: no (1) * ``uint64``: no (1) * ``int8``: no (1) * ``int16``: no (1) * ``int32``: no (1) * ``int64``: no (1) * ``float16``: no (1) * ``float32``: no (1) * ``float64``: no (1) * ``float128``: no (1) * ``bool``: no (1) - (1) This augmenter uses AllChannelsHistogramEqualization, which only supports ``uint8``.
Parameters: - from_colorspace ({“RGB”, “BGR”, “HSV”, “HLS”, “Lab”}, optional) – Colorspace of the input images.
If any input image has only one or zero channels, this setting will be
ignored and it will be assumed that the input is grayscale.
If a fourth channel is present in an input image, it will be removed
before the colorspace conversion and later re-added.
See also
imgaug.augmenters.color.change_colorspace_()
for details. - to_colorspace ({“Lab”, “HLS”, “HSV”}, optional) – Colorspace in which to perform Histogram Equalization. For
Lab
, the equalization will only be applied to the first channel (L
), forHLS
to the second (L
) and forHSV
to the third (V
). To apply histogram equalization to all channels of an input image (without colorspace conversion), seeimgaug.augmenters.contrast.AllChannelsHistogramEqualization
. - 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.HistogramEqualization()
Create an augmenter that converts images to
HLS
/HSV
/Lab
colorspaces, extracts intensity-related channels (i.e.L
/V
/L
), applies histogram equalization to these channels and converts back to the input colorspace.>>> aug = iaa.Alpha((0.0, 1.0), iaa.HistogramEqualization())
Same as in the previous example, but alpha blends the result, leading to various strengths of contrast normalization.
>>> aug = iaa.HistogramEqualization( >>> from_colorspace=iaa.CSPACE_BGR, >>> to_colorspace=iaa.CSPACE_HSV)
Same as in the first example, but the colorspace of input images has to be
BGR
(instead of defaultRGB
) and the histogram equalization is applied to theV
channel inHSV
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 -
BGR
= 'BGR'¶
-
HLS
= 'HLS'¶
-
HSV
= 'HSV'¶
-
Lab
= 'Lab'¶
-
RGB
= 'RGB'¶
- from_colorspace ({“RGB”, “BGR”, “HSV”, “HLS”, “Lab”}, optional) – Colorspace of the input images.
If any input image has only one or zero channels, this setting will be
ignored and it will be assumed that the input is grayscale.
If a fourth channel is present in an input image, it will be removed
before the colorspace conversion and later re-added.
See also
-
class
imgaug.augmenters.contrast.
LinearContrast
(alpha=1, per_channel=False, name=None, deterministic=False, random_state=None)[source]¶ Bases:
imgaug.augmenters.contrast._ContrastFuncWrapper
Adjust contrast by scaling each pixel to
127 + alpha*(v-127)
.dtype support:
See :func:`imgaug.augmenters.contrast.adjust_contrast_linear`.
Parameters: alpha (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – Multiplier to linearly pronounce (
>1.0
), dampen (0.0
to1.0
) or invert (<0.0
) the difference between each pixel value and the dtype’s center value, e.g.127
foruint8
.- If a number, then that value will be used for all images.
- If a tuple
(a, b)
, then a value from the interval[a, b]
will be used 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.
per_channel (bool or float, optional) – Whether to use the same value for all channels (
False
) or to sample a new value for each channel (True
). If this value is a floatp
, then forp
percent of all images per_channel will be treated asTrue
, otherwise asFalse
.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.LinearContrast((0.4, 1.6))
Modify the contrast of images according to 127 + alpha*(v-127)`, where
v
is a pixel value andalpha
is sampled uniformly from the interval[0.4, 1.6]
(once per image).>>> aug = iaa.LinearContrast((0.4, 1.6), per_channel=True)
Same as in the previous example, but
alpha
is sampled once per image and 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
-
class
imgaug.augmenters.contrast.
LogContrast
(gain=1, per_channel=False, name=None, deterministic=False, random_state=None)[source]¶ Bases:
imgaug.augmenters.contrast._ContrastFuncWrapper
Adjust image contrast by scaling pixels to
255*gain*log_2(1+v/255)
.This augmenter is fairly similar to
imgaug.augmenters.arithmetic.Multiply
.dtype support:
See :func:`imgaug.augmenters.contrast.adjust_contrast_log`.
Parameters: gain (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – Multiplier for the logarithm result. Values around
1.0
lead to a contrast-adjusted images. Values above1.0
quickly lead to partially broken images due to exceeding the datatype’s value range.- If a number, then that value will be used for all images.
- If a tuple
(a, b)
, then a value from the interval[a, b]
will uniformly sampled be used 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.
per_channel (bool or float, optional) – Whether to use the same value for all channels (
False
) or to sample a new value for each channel (True
). If this value is a floatp
, then forp
percent of all images per_channel will be treated asTrue
, otherwise asFalse
.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.LogContrast(gain=(0.6, 1.4))
Modify the contrast of images according to
255*gain*log_2(1+v/255)
, wherev
is a pixel value andgain
is sampled uniformly from the interval[0.6, 1.4]
(once per image).>>> aug = iaa.LogContrast(gain=(0.6, 1.4), per_channel=True)
Same as in the previous example, but
gain
is sampled once per image and 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
-
class
imgaug.augmenters.contrast.
SigmoidContrast
(gain=10, cutoff=0.5, per_channel=False, name=None, deterministic=False, random_state=None)[source]¶ Bases:
imgaug.augmenters.contrast._ContrastFuncWrapper
Adjust image contrast to
255*1/(1+exp(gain*(cutoff-I_ij/255)))
.Values in the range
gain=(5, 20)
andcutoff=(0.25, 0.75)
seem to be sensible.dtype support:
See :func:`imgaug.augmenters.contrast.adjust_contrast_sigmoid`.
Parameters: gain (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – Multiplier for the sigmoid function’s output. Higher values lead to quicker changes from dark to light pixels.
- If a number, then that value will be used for all images.
- If a tuple
(a, b)
, then a value from the interval[a, b]
will be sampled uniformly 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.
cutoff (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – Cutoff that shifts the sigmoid function in horizontal direction. Higher values mean that the switch from dark to light pixels happens later, i.e. the pixels will remain darker.
- If a number, then that value will be used for all images.
- If a tuple
(a, b)
, then a value from the range[a, b]
will be used 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.
per_channel (bool or float, optional) – Whether to use the same value for all channels (
False
) or to sample a new value for each channel (True
). If this value is a floatp
, then forp
percent of all images per_channel will be treated asTrue
, otherwise asFalse
.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.SigmoidContrast(gain=(3, 10), cutoff=(0.4, 0.6))
Modify the contrast of images according to
255*1/(1+exp(gain*(cutoff-v/255)))
, wherev
is a pixel value,gain
is sampled uniformly from the interval[3, 10]
(once per image) andcutoff
is sampled uniformly from the interval[0.4, 0.6]
(also once per image).>>> aug = iaa.SigmoidContrast( >>> gain=(3, 10), cutoff=(0.4, 0.6), per_channel=True)
Same as in the previous example, but
gain
andcutoff
are each sampled once per image and 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
-
imgaug.augmenters.contrast.
adjust_contrast_gamma
(arr, gamma)[source]¶ Adjust image contrast by scaling pixel values to
255*((v/255)**gamma)
.dtype support:
* ``uint8``: yes; fully tested (1) (2) (3) * ``uint16``: yes; tested (2) (3) * ``uint32``: yes; tested (2) (3) * ``uint64``: yes; tested (2) (3) (4) * ``int8``: limited; tested (2) (3) (5) * ``int16``: limited; tested (2) (3) (5) * ``int32``: limited; tested (2) (3) (5) * ``int64``: limited; tested (2) (3) (4) (5) * ``float16``: limited; tested (5) * ``float32``: limited; tested (5) * ``float64``: limited; tested (5) * ``float128``: no (6) * ``bool``: no (7) - (1) Handled by ``cv2``. Other dtypes are handled by ``skimage``. - (2) Normalization is done as ``I_ij/max``, where ``max`` is the maximum value of the dtype, e.g. 255 for ``uint8``. The normalization is reversed afterwards, e.g. ``result*255`` for ``uint8``. - (3) Integer-like values are not rounded after applying the contrast adjustment equation (before inverting the normalization to ``[0.0, 1.0]`` space), i.e. projection from continuous space to discrete happens according to floor function. - (4) Note that scikit-image doc says that integers are converted to ``float64`` values before applying the contrast normalization method. This might lead to inaccuracies for large 64bit integer values. Tests showed no indication of that happening though. - (5) Must not contain negative values. Values >=0 are fully supported. - (6) Leads to error in scikit-image. - (7) Does not make sense for contrast adjustments.
Parameters: - arr (numpy.ndarray) – Array for which to adjust the contrast. Dtype
uint8
is fastest. - gamma (number) – Exponent for the contrast adjustment. Higher values darken the image.
Returns: Array with adjusted contrast.
Return type: numpy.ndarray
- arr (numpy.ndarray) – Array for which to adjust the contrast. Dtype
-
imgaug.augmenters.contrast.
adjust_contrast_linear
(arr, alpha)[source]¶ Adjust contrast by scaling each pixel to
127 + alpha*(v-127)
.dtype support:
* ``uint8``: yes; fully tested (1) (2) * ``uint16``: yes; tested (2) * ``uint32``: yes; tested (2) * ``uint64``: no (3) * ``int8``: yes; tested (2) * ``int16``: yes; tested (2) * ``int32``: yes; tested (2) * ``int64``: no (2) * ``float16``: yes; tested (2) * ``float32``: yes; tested (2) * ``float64``: yes; tested (2) * ``float128``: no (2) * ``bool``: no (4) - (1) Handled by ``cv2``. Other dtypes are handled by raw ``numpy``. - (2) Only tested for reasonable alphas with up to a value of around ``100``. - (3) Conversion to ``float64`` is done during augmentation, hence ``uint64``, ``int64``, and ``float128`` support cannot be guaranteed. - (4) Does not make sense for contrast adjustments.
Parameters: - arr (numpy.ndarray) – Array for which to adjust the contrast. Dtype
uint8
is fastest. - alpha (number) – Multiplier to linearly pronounce (
>1.0
), dampen (0.0
to1.0
) or invert (<0.0
) the difference between each pixel value and the dtype’s center value, e.g.127
foruint8
.
Returns: Array with adjusted contrast.
Return type: numpy.ndarray
- arr (numpy.ndarray) – Array for which to adjust the contrast. Dtype
-
imgaug.augmenters.contrast.
adjust_contrast_log
(arr, gain)[source]¶ Adjust image contrast by scaling pixels to
255*gain*log_2(1+v/255)
.dtype support:
* ``uint8``: yes; fully tested (1) (2) (3) * ``uint16``: yes; tested (2) (3) * ``uint32``: no; tested (2) (3) (8) * ``uint64``: no; tested (2) (3) (4) (8) * ``int8``: limited; tested (2) (3) (5) * ``int16``: limited; tested (2) (3) (5) * ``int32``: no; tested (2) (3) (5) (8) * ``int64``: no; tested (2) (3) (4) (5) (8) * ``float16``: limited; tested (5) * ``float32``: limited; tested (5) * ``float64``: limited; tested (5) * ``float128``: no (6) * ``bool``: no (7) - (1) Handled by ``cv2``. Other dtypes are handled by ``skimage``. - (2) Normalization is done as ``I_ij/max``, where ``max`` is the maximum value of the dtype, e.g. 255 for ``uint8``. The normalization is reversed afterwards, e.g. ``result*255`` for ``uint8``. - (3) Integer-like values are not rounded after applying the contrast adjustment equation (before inverting the normalization to ``[0.0, 1.0]`` space), i.e. projection from continuous space to discrete happens according to floor function. - (4) Note that scikit-image doc says that integers are converted to ``float64`` values before applying the contrast normalization method. This might lead to inaccuracies for large 64bit integer values. Tests showed no indication of that happening though. - (5) Must not contain negative values. Values >=0 are fully supported. - (6) Leads to error in scikit-image. - (7) Does not make sense for contrast adjustments. - (8) No longer supported since numpy 1.17. Previously: 'yes' for ``uint32``, ``uint64``; 'limited' for ``int32``, ``int64``.
Parameters: - arr (numpy.ndarray) – Array for which to adjust the contrast. Dtype
uint8
is fastest. - gain (number) – Multiplier for the logarithm result. Values around 1.0 lead to a contrast-adjusted images. Values above 1.0 quickly lead to partially broken images due to exceeding the datatype’s value range.
Returns: Array with adjusted contrast.
Return type: numpy.ndarray
- arr (numpy.ndarray) – Array for which to adjust the contrast. Dtype
-
imgaug.augmenters.contrast.
adjust_contrast_sigmoid
(arr, gain, cutoff)[source]¶ Adjust image contrast to
255*1/(1+exp(gain*(cutoff-I_ij/255)))
.dtype support:
* ``uint8``: yes; fully tested (1) (2) (3) * ``uint16``: yes; tested (2) (3) * ``uint32``: yes; tested (2) (3) * ``uint64``: yes; tested (2) (3) (4) * ``int8``: limited; tested (2) (3) (5) * ``int16``: limited; tested (2) (3) (5) * ``int32``: limited; tested (2) (3) (5) * ``int64``: limited; tested (2) (3) (4) (5) * ``float16``: limited; tested (5) * ``float32``: limited; tested (5) * ``float64``: limited; tested (5) * ``float128``: no (6) * ``bool``: no (7) - (1) Handled by ``cv2``. Other dtypes are handled by ``skimage``. - (2) Normalization is done as ``I_ij/max``, where ``max`` is the maximum value of the dtype, e.g. 255 for ``uint8``. The normalization is reversed afterwards, e.g. ``result*255`` for ``uint8``. - (3) Integer-like values are not rounded after applying the contrast adjustment equation before inverting the normalization to ``[0.0, 1.0]`` space), i.e. projection from continuous space to discrete happens according to floor function. - (4) Note that scikit-image doc says that integers are converted to ``float64`` values before applying the contrast normalization method. This might lead to inaccuracies for large 64bit integer values. Tests showed no indication of that happening though. - (5) Must not contain negative values. Values >=0 are fully supported. - (6) Leads to error in scikit-image. - (7) Does not make sense for contrast adjustments.
Parameters: - arr (numpy.ndarray) – Array for which to adjust the contrast. Dtype
uint8
is fastest. - gain (number) – Multiplier for the sigmoid function’s output. Higher values lead to quicker changes from dark to light pixels.
- cutoff (number) – Cutoff that shifts the sigmoid function in horizontal direction. Higher values mean that the switch from dark to light pixels happens later, i.e. the pixels will remain darker.
Returns: Array with adjusted contrast.
Return type: numpy.ndarray
- arr (numpy.ndarray) – Array for which to adjust the contrast. Dtype