imgaug.parameters

Classes and methods to use for parameters of augmenters.

This module contains e.g. classes representing probability distributions (guassian, poisson etc.), classes representing noise sources and methods to normalize parameter-related user inputs.

class imgaug.parameters.Absolute(other_param)[source]

Bases: imgaug.parameters.StochasticParameter

Convert the samples of another parameter to their absolute values.

Parameters:other_param (imgaug.parameters.StochasticParameter) – Other parameter which’s sampled values are to be modified.

Examples

>>> import imgaug.parameters as iap
>>> param = iap.Absolute(iap.Uniform(-1.0, 1.0))

Convert a uniform distribution from [-1.0, 1.0) to [0.0, 1.0].

Methods

copy(self) Create a shallow copy of this parameter.
deepcopy(self) Create a deep copy of this parameter.
draw_distribution_graph(self[, title, size, …]) Generate an image visualizing the parameter’s sample distribution.
draw_sample(self[, random_state]) Draws a single sample value from this parameter.
draw_samples(self, size[, random_state]) Draw one or more samples from the parameter.
class imgaug.parameters.Add(other_param, val, elementwise=False)[source]

Bases: imgaug.parameters.StochasticParameter

Add to the samples of another stochastic parameter.

Parameters:
  • other_param (number or tuple of number or list of number or imgaug.parameters.StochasticParameter) – Samples of val will be added to samples of this parameter. Let S be the requested shape of samples, then the datatype behaviour is as follows:

    • If a single number, this number will be used as a constant value to fill an array of shape S.
    • If a tuple of two number s (a, b), an array of shape S will be filled with uniformly sampled values from the continuous interval [a, b).
    • If a list of number, an array of shape S will be filled with randomly picked values from the list.
    • If a StochasticParameter, that parameter will be queried once per call to generate an array of shape S.

    “per call” denotes a call of Add.draw_sample() or Add.draw_samples().

  • val (number or tuple of two number or list of number or imgaug.parameters.StochasticParameter) – Value to add to the samples of other_param. Datatype behaviour is analogous to other_param, though if elementwise=False (the default), only a single sample will be generated per call instead of S.

  • elementwise (bool, optional) – Controls the sampling behaviour of val. If set to False, a single samples will be requested from val and used as the constant multiplier. If set to True, samples of shape S will be requested from val and added elementwise with the samples of other_param.

Examples

>>> import imgaug.parameters as iap
>>> param = iap.Add(Uniform(0.0, 1.0), 1.0)

Convert a uniform distribution from [0.0, 1.0) to [1.0, 2.0).

Methods

copy(self) Create a shallow copy of this parameter.
deepcopy(self) Create a deep copy of this parameter.
draw_distribution_graph(self[, title, size, …]) Generate an image visualizing the parameter’s sample distribution.
draw_sample(self[, random_state]) Draws a single sample value from this parameter.
draw_samples(self, size[, random_state]) Draw one or more samples from the parameter.
class imgaug.parameters.Beta(alpha, beta, epsilon=0.0001)[source]

Bases: imgaug.parameters.StochasticParameter

Parameter that resembles a (continuous) beta distribution.

Parameters:
  • alpha (number or tuple of number or list of number or imgaug.parameters.StochasticParameter) – alpha parameter of the beta distribution. Expected value range is (0, inf). Values below 0 are automatically clipped to 0+epsilon.

    • If a single number, this number will be used as a constant value.
    • If a tuple of two number s (a, b), the value will be sampled from the continuous interval [a, b) once per call.
    • If a list of number, a random value will be picked from the list once per call.
    • If a StochasticParameter, that parameter will be queried once per call.

    “per call” denotes a call of Beta.draw_sample() or Beta.draw_samples().

  • beta (number or tuple of number or list of number or imgaug.parameters.StochasticParameter) – Beta parameter of the beta distribution. Analogous to alpha.

  • epsilon (number) – Clipping parameter. If alpha or beta end up <=0, they are clipped to 0+epsilon.

Examples

>>> import imgaug.parameters as iap
>>> param = iap.Beta(0.4, 0.6)

Create a beta distribution with alpha=0.4 and beta=0.6.

Methods

copy(self) Create a shallow copy of this parameter.
deepcopy(self) Create a deep copy of this parameter.
draw_distribution_graph(self[, title, size, …]) Generate an image visualizing the parameter’s sample distribution.
draw_sample(self[, random_state]) Draws a single sample value from this parameter.
draw_samples(self, size[, random_state]) Draw one or more samples from the parameter.
class imgaug.parameters.Binomial(p)[source]

Bases: imgaug.parameters.StochasticParameter

Binomial distribution.

Parameters:

p (number or tuple of number or list of number or imgaug.parameters.StochasticParameter) – Probability of the binomial distribution. Expected to be in the interval [0.0, 1.0].

  • If a single number, this number will be used as a constant value.
  • If a tuple of two number s (a, b), the value will be sampled from the continuous interval [a, b) once per call.
  • If a list of number, a random value will be picked from the list once per call.
  • If a StochasticParameter, that parameter will be queried once per call.

“per call” denotes a call of Binomial.draw_sample() or Binomial.draw_samples().

Examples

>>> import imgaug.parameters as iap
>>> param = iap.Binomial(Uniform(0.01, 0.2))

Create a binomial distribution that uses a varying probability between 0.01 and 0.2, randomly and uniformly estimated once per sampling call.

Methods

copy(self) Create a shallow copy of this parameter.
deepcopy(self) Create a deep copy of this parameter.
draw_distribution_graph(self[, title, size, …]) Generate an image visualizing the parameter’s sample distribution.
draw_sample(self[, random_state]) Draws a single sample value from this parameter.
draw_samples(self, size[, random_state]) Draw one or more samples from the parameter.
class imgaug.parameters.ChiSquare(df)[source]

Bases: imgaug.parameters.StochasticParameter

Parameter that resembles a (continuous) chi-square distribution.

This is a wrapper around numpy’s numpy.random.chisquare().

Parameters:

df (int or tuple of two int or list of int or imgaug.parameters.StochasticParameter) –

Degrees of freedom. Expected value range is [1, inf).

  • If a single int, this int will be used as a constant value.
  • If a tuple of two int s (a, b), the value will be sampled from the discrete interval [a..b] once per call.
  • If a list of int, a random value will be picked from the list once per call.
  • If a StochasticParameter, that parameter will be queried once per call.

“per call” denotes a call of ChiSquare.draw_sample() or ChiSquare.draw_samples().

Examples

>>> import imgaug.parameters as iap
>>> param = iap.ChiSquare(df=2)

Create a chi-square distribution with two degrees of freedom.

Methods

copy(self) Create a shallow copy of this parameter.
deepcopy(self) Create a deep copy of this parameter.
draw_distribution_graph(self[, title, size, …]) Generate an image visualizing the parameter’s sample distribution.
draw_sample(self[, random_state]) Draws a single sample value from this parameter.
draw_samples(self, size[, random_state]) Draw one or more samples from the parameter.
class imgaug.parameters.Choice(a, replace=True, p=None)[source]

Bases: imgaug.parameters.StochasticParameter

Parameter that samples value from a list of allowed values.

Parameters:
  • a (iterable) – List of allowed values. Usually expected to be int s, float s or str s. May also contain StochasticParameter s. Each StochasticParameter that is randomly picked will automatically be replaced by a sample of itself (or by N samples if the parameter was picked N times).
  • replace (bool, optional) – Whether to perform sampling with or without replacing.
  • p (None or iterable of number, optional) – Probabilities of each element in a. Must have the same length as a (if provided).

Examples

>>> import imgaug.parameters as iap
>>> param = iap.Choice([5, 17, 25], p=[0.25, 0.5, 0.25])
>>> sample = param.draw_sample()
>>> assert sample in [5, 17, 25]

Create and sample from a parameter, which will produce with 50% probability the sample 17 and in the other 50% of all cases the sample 5 or 25..

Methods

copy(self) Create a shallow copy of this parameter.
deepcopy(self) Create a deep copy of this parameter.
draw_distribution_graph(self[, title, size, …]) Generate an image visualizing the parameter’s sample distribution.
draw_sample(self[, random_state]) Draws a single sample value from this parameter.
draw_samples(self, size[, random_state]) Draw one or more samples from the parameter.
class imgaug.parameters.Clip(other_param, minval=None, maxval=None)[source]

Bases: imgaug.parameters.StochasticParameter

Clip another parameter to a defined value range.

Parameters:
  • other_param (imgaug.parameters.StochasticParameter) – The other parameter, which’s values are to be clipped.
  • minval (None or number, optional) – The minimum value to use. If None, no minimum will be used.
  • maxval (None or number, optional) – The maximum value to use. If None, no maximum will be used.

Examples

>>> import imgaug.parameters as iap
>>> param = iap.Clip(Normal(0, 1.0), minval=-2.0, maxval=2.0)

Create a standard gaussian distribution, which’s values never go below -2.0 or above 2.0. Note that this will lead to small “bumps” of higher probability at -2.0 and 2.0, as values below/above these will be clipped to them. For smoother limitations on gaussian distributions, see TruncatedNormal.

Methods

copy(self) Create a shallow copy of this parameter.
deepcopy(self) Create a deep copy of this parameter.
draw_distribution_graph(self[, title, size, …]) Generate an image visualizing the parameter’s sample distribution.
draw_sample(self[, random_state]) Draws a single sample value from this parameter.
draw_samples(self, size[, random_state]) Draw one or more samples from the parameter.
class imgaug.parameters.Deterministic(value)[source]

Bases: imgaug.parameters.StochasticParameter

Parameter that is a constant value.

If N values are sampled from this parameter, it will return N times V, where V is the constant value.

Parameters:value (number or str or imgaug.parameters.StochasticParameter) – A constant value to use. A string may be provided to generate arrays of strings. If this is a StochasticParameter, a single value will be sampled from it exactly once and then used as the constant value.

Examples

>>> import imgaug.parameters as iap
>>> param = iap.Deterministic(10)
>>> param.draw_sample()
10

Will always sample the value 10.

Methods

copy(self) Create a shallow copy of this parameter.
deepcopy(self) Create a deep copy of this parameter.
draw_distribution_graph(self[, title, size, …]) Generate an image visualizing the parameter’s sample distribution.
draw_sample(self[, random_state]) Draws a single sample value from this parameter.
draw_samples(self, size[, random_state]) Draw one or more samples from the parameter.
class imgaug.parameters.DeterministicList(values)[source]

Bases: imgaug.parameters.StochasticParameter

Parameter that repeats elements from a list in the given order.

E.g. of samples of shape (A, B, C) are requested, this parameter will return the first A*B*C elements, reshaped to (A, B, C) from the provided list. If the list contains less than A*B*C elements, it will (by default) be tiled until it is long enough (i.e. the sampling will start again at the first element, if necessary multiple times).

Added in 0.4.0.

Parameters:values (ndarray or iterable of number) – An iterable of values to sample from in the order within the iterable.

Methods

copy(self) Create a shallow copy of this parameter.
deepcopy(self) Create a deep copy of this parameter.
draw_distribution_graph(self[, title, size, …]) Generate an image visualizing the parameter’s sample distribution.
draw_sample(self[, random_state]) Draws a single sample value from this parameter.
draw_samples(self, size[, random_state]) Draw one or more samples from the parameter.
class imgaug.parameters.DiscreteUniform(a, b)[source]

Bases: imgaug.parameters.StochasticParameter

Uniform distribution over the discrete interval [a..b].

Parameters:
  • a (int or tuple of int or list of int or imgaug.parameters.StochasticParameter) – Lower bound of the interval. If a>b, a and b will automatically be flipped. If a==b, all generated values will be identical to a.

    • If a single int, this int will be used as a constant value.
    • If a tuple of two int s (a, b), the value will be sampled from the discrete interval [a..b] once per call.
    • If a list of int, a random value will be picked from the list once per call.
    • If a StochasticParameter, that parameter will be queried once per call.

    “per call” denotes a call of DiscreteUniform.draw_sample() or DiscreteUniform.draw_samples().

  • b (int or imgaug.parameters.StochasticParameter) – Upper bound of the interval. Analogous to a.

Examples

>>> import imgaug.parameters as iap
>>> param = iap.DiscreteUniform(10, Choice([20, 30, 40]))
>>> sample = param.draw_sample()
>>> assert 10 <= sample <= 40

Create a discrete uniform distribution which’s interval differs between calls and can be [10..20], [10..30] or [10..40].

Methods

copy(self) Create a shallow copy of this parameter.
deepcopy(self) Create a deep copy of this parameter.
draw_distribution_graph(self[, title, size, …]) Generate an image visualizing the parameter’s sample distribution.
draw_sample(self[, random_state]) Draws a single sample value from this parameter.
draw_samples(self, size[, random_state]) Draw one or more samples from the parameter.
class imgaug.parameters.Discretize(other_param, round=True)[source]

Bases: imgaug.parameters.StochasticParameter

Convert a continuous distribution to a discrete one.

This will round the values and then cast them to integers. Values sampled from already discrete distributions are not changed.

Parameters:
  • other_param (imgaug.parameters.StochasticParameter) – The other parameter, which’s values are to be discretized.

  • round (bool, optional) – Whether to round before converting to integer dtype.

    Added in 0.4.0.

Examples

>>> import imgaug.parameters as iap
>>> param = iap.Discretize(iap.Normal(0, 1.0))

Create a discrete standard gaussian distribution.

Methods

copy(self) Create a shallow copy of this parameter.
deepcopy(self) Create a deep copy of this parameter.
draw_distribution_graph(self[, title, size, …]) Generate an image visualizing the parameter’s sample distribution.
draw_sample(self[, random_state]) Draws a single sample value from this parameter.
draw_samples(self, size[, random_state]) Draw one or more samples from the parameter.
class imgaug.parameters.Divide(other_param, val, elementwise=False)[source]

Bases: imgaug.parameters.StochasticParameter

Divide the samples of another stochastic parameter.

This parameter will automatically prevent division by zero (uses 1.0) as the denominator in these cases.

Parameters:
  • other_param (number or tuple of number or list of number or imgaug.parameters.StochasticParameter) – Other parameter which’s sampled values are to be divided by val. Let S be the requested shape of samples, then the datatype behaviour is as follows:

    • If a single number, this number will be used as a constant value to fill an array of shape S.
    • If a tuple of two number s (a, b), an array of shape S will be filled with uniformly sampled values from the continuous interval [a, b).
    • If a list of number, an array of shape S will be filled with randomly picked values from the list.
    • If a StochasticParameter, that parameter will be queried once per call to generate an array of shape S.

    “per call” denotes a call of Divide.draw_sample() or Divide.draw_samples().

  • val (number or tuple of number or list of number or imgaug.parameters.StochasticParameter) – Denominator to use. Datatype behaviour is analogous to other_param, though if elementwise=False (the default), only a single sample will be generated per call instead of S.

  • elementwise (bool, optional) – Controls the sampling behaviour of val. If set to False, a single samples will be requested from val and used as the constant denominator. If set to True, samples of shape S will be requested from val and used to divide the samples of other_param elementwise.

Examples

>>> import imgaug.parameters as iap
>>> param = iap.Divide(iap.Uniform(0.0, 1.0), 2)

Convert a uniform distribution [0.0, 1.0) to [0, 0.5).

Methods

copy(self) Create a shallow copy of this parameter.
deepcopy(self) Create a deep copy of this parameter.
draw_distribution_graph(self[, title, size, …]) Generate an image visualizing the parameter’s sample distribution.
draw_sample(self[, random_state]) Draws a single sample value from this parameter.
draw_samples(self, size[, random_state]) Draw one or more samples from the parameter.
class imgaug.parameters.ForceSign(other_param, positive, mode='invert', reroll_count_max=2)[source]

Bases: imgaug.parameters.StochasticParameter

Convert a parameter’s samples to either positive or negative values.

Parameters:
  • other_param (imgaug.parameters.StochasticParameter) – Other parameter which’s sampled values are to be modified.
  • positive (bool) – Whether to force all signs to be positive (True) or negative (False).
  • mode ({‘invert’, ‘reroll’}, optional) – Method to change the signs. Valid values are invert and reroll. invert means that wrong signs are simply flipped. reroll means that all samples with wrong signs are sampled again, optionally many times, until they randomly end up having the correct sign.
  • reroll_count_max (int, optional) – If mode is set to reroll, this determines how often values may be rerolled before giving up and simply flipping the sign (as in mode="invert"). This shouldn’t be set too high, as rerolling is expensive.

Examples

>>> import imgaug.parameters as iap
>>> param = iap.ForceSign(iap.Poisson(1), positive=False)

Create a poisson distribution with alpha=1 that is flipped towards negative values.

Methods

copy(self) Create a shallow copy of this parameter.
deepcopy(self) Create a deep copy of this parameter.
draw_distribution_graph(self[, title, size, …]) Generate an image visualizing the parameter’s sample distribution.
draw_sample(self[, random_state]) Draws a single sample value from this parameter.
draw_samples(self, size[, random_state]) Draw one or more samples from the parameter.
class imgaug.parameters.FrequencyNoise(exponent=(-4, 4), size_px_max=(4, 32), upscale_method=['linear', 'nearest'])[source]

Bases: imgaug.parameters.StochasticParameter

Parameter to generate noise of varying frequencies.

This parameter expects to sample noise for 2d planes, i.e. for sizes (H, W, [C]) and will return a value in the range [0.0, 1.0] per spatial location in that plane.

The exponent controls the frequencies and therefore noise patterns. Small values (around -4.0) will result in large blobs. Large values (around 4.0) will result in small, repetitive patterns.

The noise is sampled from low resolution planes and upscaled to the requested height and width. The size of the low resolution plane may be defined (high values can be slow) and the interpolation method for upscaling can be set.

Parameters:
  • exponent (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – Exponent to use when scaling in the frequency domain. Sane values are in the range -4 (large blobs) to 4 (small patterns). To generate cloud-like structures, use roughly -2.

    • If a single number, this number will be used as a constant value.
    • If a tuple of two number s (a, b), the value will be sampled from the continuous interval [a, b) once per call.
    • If a list of number, a random value will be picked from the list once per call.
    • If a StochasticParameter, that parameter will be queried once per call.
  • size_px_max (int or tuple of int or list of int or imgaug.parameters.StochasticParameter, optional) – Maximum height and width in pixels of the low resolution plane. Upon any sampling call, the requested shape will be downscaled until the height or width (whichever is larger) does not exceed this maximum value anymore. Then the noise will be sampled at that shape and later upscaled back to the requested shape.

    • If a single int, this int will be used as a constant value.
    • If a tuple of two int s (a, b), the value will be sampled from the discrete interval [a..b] once per call.
    • If a list of int, a random value will be picked from the list once per call.
    • If a StochasticParameter, that parameter will be queried once per call.

    “per call” denotes a call of FrequencyNoise.draw_sample() or FrequencyNoise.draw_samples().

  • upscale_method (imgaug.ALL or str or list of str or imgaug.parameters.StochasticParameter, optional) – After generating the noise maps in low resolution environments, they have to be upscaled to the originally requested shape (i.e. usually the image size). This parameter controls the interpolation method to use. See also imresize_many_images() for a description of possible values.

    • If imgaug.ALL, then either nearest or linear or area or cubic is picked per iteration (all same probability).
    • If str, then that value will always be used as the method (must be nearest or linear or area or cubic).
    • If list of str, then a random value will be picked from that list per call.
    • If StochasticParameter, then a random value will be sampled from that parameter per call.

Examples

>>> import imgaug.parameters as iap
>>> param = iap.FrequencyNoise(
>>>     exponent=-2,
>>>     size_px_max=(16, 32),
>>>     upscale_method="linear")

Create a parameter that produces noise with cloud-like patterns.

Methods

copy(self) Create a shallow copy of this parameter.
deepcopy(self) Create a deep copy of this parameter.
draw_distribution_graph(self[, title, size, …]) Generate an image visualizing the parameter’s sample distribution.
draw_sample(self[, random_state]) Draws a single sample value from this parameter.
draw_samples(self, size[, random_state]) Draw one or more samples from the parameter.
class imgaug.parameters.FromLowerResolution(other_param, size_percent=None, size_px=None, method='nearest', min_size=1)[source]

Bases: imgaug.parameters.StochasticParameter

Parameter to sample from other parameters at lower image resolutions.

This parameter is intended to be used with parameters that would usually sample one value per pixel (or one value per pixel and channel). Instead of sampling from the other parameter at full resolution, it samples at lower resolution, e.g. 0.5*H x 0.5*W with H being the height and W being the width. After the low-resolution sampling this parameter then upscales the result to HxW.

This parameter is intended to produce coarse samples. E.g. combining this with Binomial can lead to large rectangular areas of 1 s and 0 s.

Parameters:
  • other_param (imgaug.parameters.StochasticParameter) – The other parameter which is to be sampled on a coarser image.
  • size_percent (None or number or iterable of number or imgaug.parameters.StochasticParameter, optional) – Size of the 2d sampling plane in percent of the requested size. I.e. this is relative to the size provided in the call to draw_samples(size). Lower values will result in smaller sampling planes, which are then upsampled to size. This means that lower values will result in larger rectangles. The size may be provided as a constant value or a tuple (a, b), which will automatically be converted to the continuous uniform range [a, b) or a StochasticParameter, which will be queried per call to FromLowerResolution.draw_sample() and FromLowerResolution.draw_samples().
  • size_px (None or number or iterable of numbers or imgaug.parameters.StochasticParameter, optional) – Size of the 2d sampling plane in pixels. Lower values will result in smaller sampling planes, which are then upsampled to the input size of draw_samples(size). This means that lower values will result in larger rectangles. The size may be provided as a constant value or a tuple (a, b), which will automatically be converted to the discrete uniform range [a..b] or a StochasticParameter, which will be queried once per call to FromLowerResolution.draw_sample() and FromLowerResolution.draw_samples().
  • method (str or int or imgaug.parameters.StochasticParameter, optional) – Upsampling/interpolation method to use. This is used after the sampling is finished and the low resolution plane has to be upsampled to the requested size in draw_samples(size, ...). The method may be the same as in imresize_many_images(). Usually nearest or linear are good choices. nearest will result in rectangles with sharp edges and linear in rectangles with blurry and round edges. The method may be provided as a StochasticParameter, which will be queried once per call to FromLowerResolution.draw_sample() and FromLowerResolution.draw_samples().
  • min_size (int, optional) – Minimum size in pixels of the low resolution sampling plane.

Examples

>>> import imgaug.parameters as iap
>>> param = iap.FromLowerResolution(
>>>     Binomial(0.05),
>>>     size_px=(2, 16),
>>>     method=Choice(["nearest", "linear"]))

Samples from a binomial distribution with p=0.05. The sampling plane will always have a size HxWxC with H and W being independently sampled from [2..16] (i.e. it may range from 2x2xC up to 16x16xC max, but may also be e.g. 4x8xC). The upsampling method will be nearest in 50% of all cases and linear in the other 50 percent. The result will sometimes be rectangular patches of sharp 1 s surrounded by 0 s and sometimes blurry blobs of 1``s, surrounded by values ``<1.0.

Methods

copy(self) Create a shallow copy of this parameter.
deepcopy(self) Create a deep copy of this parameter.
draw_distribution_graph(self[, title, size, …]) Generate an image visualizing the parameter’s sample distribution.
draw_sample(self[, random_state]) Draws a single sample value from this parameter.
draw_samples(self, size[, random_state]) Draw one or more samples from the parameter.
class imgaug.parameters.IterativeNoiseAggregator(other_param, iterations=(1, 3), aggregation_method=['max', 'avg'])[source]

Bases: imgaug.parameters.StochasticParameter

Aggregate multiple iterations of samples from another parameter.

This is supposed to be used in conjunction with SimplexNoise or FrequencyNoise. If a shape S is requested, it will request I times S samples from the underlying parameter, where I is the number of iterations. The I arrays will be combined to a single array of shape S using an aggregation method, e.g. simple averaging.

Parameters:
  • other_param (StochasticParameter) – The other parameter from which to sample one or more times.

  • iterations (int or iterable of int or list of int or imgaug.parameters.StochasticParameter, optional) –

    The number of iterations.

    • If a single int, this int will be used as a constant value.
    • If a tuple of two int s (a, b), the value will be sampled from the discrete interval [a..b] once per call.
    • If a list of int, a random value will be picked from the list once per call.
    • If a StochasticParameter, that parameter will be queried once per call.

    “per call” denotes a call of IterativeNoiseAggregator.draw_sample() or IterativeNoiseAggregator.draw_samples().

  • aggregation_method (imgaug.ALL or {‘min’, ‘avg’, ‘max’} or list of str or imgaug.parameters.StochasticParameter, optional) – The method to use to aggregate the samples of multiple iterations to a single output array. All methods combine several arrays of shape S each to a single array of shape S and hence work elementwise. Known methods are min (take the minimum over all iterations), max (take the maximum) and avg (take the average).

    • If an str, it must be one of the described methods and will be used for all calls..
    • If a list of str, it must contain one or more of the described methods and a random one will be samples once per call.
    • If imgaug.ALL, then equivalent to the list ["min", "max", "avg"].
    • If StochasticParameter, a value will be sampled from that parameter once per call and must be one of the described methods..

    “per call” denotes a call of IterativeNoiseAggregator.draw_sample() or IterativeNoiseAggregator.draw_samples().

Examples

>>> import imgaug.parameters as iap
>>> noise = iap.IterativeNoiseAggregator(
>>>     iap.SimplexNoise(),
>>>     iterations=(2, 5),
>>>     aggregation_method="max")

Create a parameter that – upon each call – generates 2 to 5 arrays of simplex noise with the same shape. Then it combines these noise maps to a single map using elementwise maximum.

Methods

copy(self) Create a shallow copy of this parameter.
deepcopy(self) Create a deep copy of this parameter.
draw_distribution_graph(self[, title, size, …]) Generate an image visualizing the parameter’s sample distribution.
draw_sample(self[, random_state]) Draws a single sample value from this parameter.
draw_samples(self, size[, random_state]) Draw one or more samples from the parameter.
class imgaug.parameters.Laplace(loc, scale)[source]

Bases: imgaug.parameters.StochasticParameter

Parameter that resembles a (continuous) laplace distribution.

This is a wrapper around numpy’s numpy.random.laplace().

Parameters:
  • loc (number or tuple of number or list of number or imgaug.parameters.StochasticParameter) – The position of the distribution peak, similar to the mean in normal distributions.

    • If a single number, this number will be used as a constant value.
    • If a tuple of two number s (a, b), the value will be sampled from the continuous interval [a, b) once per call.
    • If a list of number, a random value will be picked from the list once per call.
    • If a StochasticParameter, that parameter will be queried once per call.

    “per call” denotes a call of Laplace.draw_sample() or Laplace.draw_samples().

  • scale (number or tuple of number or list of number or imgaug.parameters.StochasticParameter) – The exponential decay factor, similar to the standard deviation in gaussian distributions. If this parameter reaches 0, the output array will be filled with loc. Datatype behaviour is the analogous to loc.

Examples

>>> import imgaug.parameters as iap
>>> param = iap.Laplace(0, 1.0)

Create a laplace distribution, which’s peak is at 0 and decay is 1.0.

Methods

copy(self) Create a shallow copy of this parameter.
deepcopy(self) Create a deep copy of this parameter.
draw_distribution_graph(self[, title, size, …]) Generate an image visualizing the parameter’s sample distribution.
draw_sample(self[, random_state]) Draws a single sample value from this parameter.
draw_samples(self, size[, random_state]) Draw one or more samples from the parameter.
class imgaug.parameters.Multiply(other_param, val, elementwise=False)[source]

Bases: imgaug.parameters.StochasticParameter

Multiply the samples of another stochastic parameter.

Parameters:
  • other_param (number or tuple of number or list of number or imgaug.parameters.StochasticParameter) – Other parameter which’s sampled values are to be multiplied with val. Let S be the requested shape of samples, then the datatype behaviour is as follows:

    • If a single number, this number will be used as a constant value to fill an array of shape S.
    • If a tuple of two number s (a, b), an array of shape S will be filled with uniformly sampled values from the continuous interval [a, b).
    • If a list of number, an array of shape S will be filled with randomly picked values from the list.
    • If a StochasticParameter, that parameter will be queried once per call to generate an array of shape S.

    “per call” denotes a call of Multiply.draw_sample() or Multiply.draw_samples().

  • val (number or tuple of number or list of number or imgaug.parameters.StochasticParameter) – Multiplier to use. Datatype behaviour is analogous to other_param, though if elementwise=False (the default), only a single sample will be generated per call instead of S.

  • elementwise (bool, optional) – Controls the sampling behaviour of val. If set to False, a single samples will be requested from val and used as the constant multiplier. If set to True, samples of shape S will be requested from val and multiplied elementwise with the samples of other_param.

Examples

>>> import imgaug.parameters as iap
>>> param = iap.Multiply(iap.Uniform(0.0, 1.0), -1)

Convert a uniform distribution from [0.0, 1.0) to (-1.0, 0.0].

Methods

copy(self) Create a shallow copy of this parameter.
deepcopy(self) Create a deep copy of this parameter.
draw_distribution_graph(self[, title, size, …]) Generate an image visualizing the parameter’s sample distribution.
draw_sample(self[, random_state]) Draws a single sample value from this parameter.
draw_samples(self, size[, random_state]) Draw one or more samples from the parameter.
imgaug.parameters.Negative(other_param, mode='invert', reroll_count_max=2)[source]

Convert another parameter’s results to negative values.

Parameters:
  • other_param (imgaug.parameters.StochasticParameter) – Other parameter which’s sampled values are to be modified.
  • mode ({‘invert’, ‘reroll’}, optional) – How to change the signs. Valid values are invert and reroll. invert means that wrong signs are simply flipped. reroll means that all samples with wrong signs are sampled again, optionally many times, until they randomly end up having the correct sign.
  • reroll_count_max (int, optional) – If mode is set to reroll, this determines how often values may be rerolled before giving up and simply flipping the sign (as in mode="invert"). This shouldn’t be set too high, as rerolling is expensive.

Examples

>>> import imgaug.parameters as iap
>>> param = iap.Negative(iap.Normal(0, 1), mode="reroll")

Create a gaussian distribution that has only negative values. If any positive value is sampled in the process, that sample is resampled up to two times to get a negative one. If it isn’t negative after the second resampling step, the sign is simply flipped.

class imgaug.parameters.Normal(loc, scale)[source]

Bases: imgaug.parameters.StochasticParameter

Parameter that resembles a normal/gaussian distribution.

Parameters:
  • loc (number or tuple of number or list of number or imgaug.parameters.StochasticParameter) –

    The mean of the normal distribution.

    • If a single number, this number will be used as a constant value.
    • If a tuple of two number s (a, b), the value will be sampled from the continuous interval [a, b) once per call.
    • If a list of number, a random value will be picked from the list once per call.
    • If a StochasticParameter, that parameter will be queried once per call.

    “per call” denotes a call of Laplace.draw_sample() or Laplace.draw_samples().

  • scale (number or tuple of number or list of number or imgaug.parameters.StochasticParameter) – The standard deviation of the normal distribution. If this parameter reaches 0, the output array will be filled with loc. Datatype behaviour is the analogous to loc.

Examples

>>> import imgaug.parameters as iap
>>> param = iap.Normal(Choice([-1.0, 1.0]), 1.0)

Create a gaussian distribution with a mean that differs by call. Samples values may sometimes follow N(-1.0, 1.0) and sometimes N(1.0, 1.0).

Methods

copy(self) Create a shallow copy of this parameter.
deepcopy(self) Create a deep copy of this parameter.
draw_distribution_graph(self[, title, size, …]) Generate an image visualizing the parameter’s sample distribution.
draw_sample(self[, random_state]) Draws a single sample value from this parameter.
draw_samples(self, size[, random_state]) Draw one or more samples from the parameter.
class imgaug.parameters.Poisson(lam)[source]

Bases: imgaug.parameters.StochasticParameter

Parameter that resembles a poisson distribution.

A poisson distribution with lambda=0 has its highest probability at point 0 and decreases quickly from there. Poisson distributions are discrete and never negative.

Parameters:

lam (number or tuple of number or list of number or imgaug.parameters.StochasticParameter) –

Lambda parameter of the poisson distribution.

  • If a single number, this number will be used as a constant value.
  • If a tuple of two number s (a, b), the value will be sampled from the continuous interval [a, b) once per call.
  • If a list of number, a random value will be picked from the list once per call.
  • If a StochasticParameter, that parameter will be queried once per call.

“per call” denotes a call of Poisson.draw_sample() or Poisson.draw_samples().

Examples

>>> import imgaug.parameters as iap
>>> param = iap.Poisson(1)
>>> sample = param.draw_sample()
>>> assert sample >= 0

Create a poisson distribution with lambda=1 and sample a value from it.

Methods

copy(self) Create a shallow copy of this parameter.
deepcopy(self) Create a deep copy of this parameter.
draw_distribution_graph(self[, title, size, …]) Generate an image visualizing the parameter’s sample distribution.
draw_sample(self[, random_state]) Draws a single sample value from this parameter.
draw_samples(self, size[, random_state]) Draw one or more samples from the parameter.
imgaug.parameters.Positive(other_param, mode='invert', reroll_count_max=2)[source]

Convert another parameter’s results to positive values.

Parameters:
  • other_param (imgaug.parameters.StochasticParameter) – Other parameter which’s sampled values are to be modified.
  • mode ({‘invert’, ‘reroll’}, optional) – How to change the signs. Valid values are invert and reroll. invert means that wrong signs are simply flipped. reroll means that all samples with wrong signs are sampled again, optionally many times, until they randomly end up having the correct sign.
  • reroll_count_max (int, optional) – If mode is set to reroll, this determines how often values may be rerolled before giving up and simply flipping the sign (as in mode="invert"). This shouldn’t be set too high, as rerolling is expensive.

Examples

>>> import imgaug.parameters as iap
>>> param = iap.Positive(iap.Normal(0, 1), mode="reroll")

Create a gaussian distribution that has only positive values. If any negative value is sampled in the process, that sample is resampled up to two times to get a positive one. If it isn’t positive after the second resampling step, the sign is simply flipped.

class imgaug.parameters.Power(other_param, val, elementwise=False)[source]

Bases: imgaug.parameters.StochasticParameter

Exponentiate the samples of another stochastic parameter.

Parameters:
  • other_param (number or tuple of number or list of number or imgaug.parameters.StochasticParameter) – Other parameter which’s sampled values are to be exponentiated by val. Let S be the requested shape of samples, then the datatype behaviour is as follows:

    • If a single number, this number will be used as a constant value to fill an array of shape S.
    • If a tuple of two number s (a, b), an array of shape S will be filled with uniformly sampled values from the continuous interval [a, b).
    • If a list of number, an array of shape S will be filled with randomly picked values from the list.
    • If a StochasticParameter, that parameter will be queried once per call to generate an array of shape S.

    “per call” denotes a call of Power.draw_sample() or Power.draw_samples().

  • val (number or tuple of number or list of number or imgaug.parameters.StochasticParameter) – Value to use exponentiate the samples of other_param. Datatype behaviour is analogous to other_param, though if elementwise=False (the default), only a single sample will be generated per call instead of S.

  • elementwise (bool, optional) – Controls the sampling behaviour of val. If set to False, a single samples will be requested from val and used as the constant multiplier. If set to True, samples of shape S will be requested from val and used to exponentiate elementwise the samples of other_param.

Examples

>>> import imgaug.parameters as iap
>>> param = iap.Power(iap.Uniform(0.0, 1.0), 2)

Converts a uniform range [0.0, 1.0) to a distribution that is peaked towards 1.0.

Methods

copy(self) Create a shallow copy of this parameter.
deepcopy(self) Create a deep copy of this parameter.
draw_distribution_graph(self[, title, size, …]) Generate an image visualizing the parameter’s sample distribution.
draw_sample(self[, random_state]) Draws a single sample value from this parameter.
draw_samples(self, size[, random_state]) Draw one or more samples from the parameter.
class imgaug.parameters.RandomSign(other_param, p_positive=0.5)[source]

Bases: imgaug.parameters.StochasticParameter

Convert a parameter’s samples randomly to positive or negative values.

Parameters:
  • other_param (imgaug.parameters.StochasticParameter) – Other parameter which’s sampled values are to be modified.
  • p_positive (number) – Fraction of values that are supposed to be turned to positive values.

Examples

>>> import imgaug.parameters as iap
>>> param = iap.RandomSign(iap.Poisson(1))

Create a poisson distribution with alpha=1 that is mirrored/copied (not flipped) at the y-axis.

Methods

copy(self) Create a shallow copy of this parameter.
deepcopy(self) Create a deep copy of this parameter.
draw_distribution_graph(self[, title, size, …]) Generate an image visualizing the parameter’s sample distribution.
draw_sample(self[, random_state]) Draws a single sample value from this parameter.
draw_samples(self, size[, random_state]) Draw one or more samples from the parameter.
class imgaug.parameters.Sigmoid(other_param, threshold=(-10, 10), activated=True, mul=1, add=0)[source]

Bases: imgaug.parameters.StochasticParameter

Apply a sigmoid function to the outputs of another parameter.

This is intended to be used in combination with SimplexNoise or FrequencyNoise. It pushes the noise values away from ~0.5 and towards 0.0 or 1.0, making the noise maps more binary.

Parameters:
  • other_param (imgaug.parameters.StochasticParameter) – The other parameter to which the sigmoid will be applied.

  • threshold (number or tuple of number or iterable of number or imgaug.parameters.StochasticParameter, optional) – Sets the value of the sigmoid’s saddle point, i.e. where values start to quickly shift from 0.0 to 1.0.

    • If a single number, this number will be used as a constant value.
    • If a tuple of two number s (a, b), the value will be sampled from the continuous interval [a, b) once per call.
    • If a list of number, a random value will be picked from the list once per call.
    • If a StochasticParameter, that parameter will be queried once per call.

    “per call” denotes a call of Sigmoid.draw_sample() or Sigmoid.draw_samples().

  • activated (bool or number, optional) – Defines whether the sigmoid is activated. If this is False, the results of other_param will not be altered. This may be set to a float p in value range``[0.0, 1.0]``, which will result in activated being True in p percent of all calls.

  • mul (number, optional) – The results of other_param will be multiplied with this value before applying the sigmoid. For noise values (range [0.0, 1.0]) this should be set to about 20.

  • add (number, optional) – This value will be added to the results of other_param before applying the sigmoid. For noise values (range [0.0, 1.0]) this should be set to about -10.0, provided mul was set to 20.

Examples

>>> import imgaug.parameters as iap
>>> param = iap.Sigmoid(
>>>     iap.SimplexNoise(),
>>>     activated=0.5,
>>>     mul=20,
>>>     add=-10)

Applies a sigmoid to simplex noise in 50% of all calls. The noise results are modified to match the sigmoid’s expected value range. The sigmoid’s outputs are in the range [0.0, 1.0].

Methods

copy(self) Create a shallow copy of this parameter.
create_for_noise(other_param[, threshold, …]) Create a Sigmoid adjusted for noise parameters.
deepcopy(self) Create a deep copy of this parameter.
draw_distribution_graph(self[, title, size, …]) Generate an image visualizing the parameter’s sample distribution.
draw_sample(self[, random_state]) Draws a single sample value from this parameter.
draw_samples(self, size[, random_state]) Draw one or more samples from the parameter.
static create_for_noise(other_param, threshold=(-10, 10), activated=True)[source]

Create a Sigmoid adjusted for noise parameters.

“noise” here denotes SimplexNoise and FrequencyNoise.

Parameters:
  • other_param (imgaug.parameters.StochasticParameter) – See __init__().
  • threshold (number or tuple of number or iterable of number or imgaug.parameters.StochasticParameter, optional) – See __init__().
  • activated (bool or number, optional) – See __init__().
Returns:

A sigmoid adjusted to be used with noise.

Return type:

Sigmoid

class imgaug.parameters.SimplexNoise(size_px_max=(2, 16), upscale_method=['linear', 'nearest'])[source]

Bases: imgaug.parameters.StochasticParameter

Parameter that generates simplex noise of varying resolutions.

This parameter expects to sample noise for 2d planes, i.e. for sizes (H, W, [C]) and will return a value in the range [0.0, 1.0] per spatial location in that plane.

The noise is sampled from low resolution planes and upscaled to the requested height and width. The size of the low resolution plane may be defined (large values can be slow) and the interpolation method for upscaling can be set.

Parameters:
  • size_px_max (int or tuple of int or list of int or imgaug.parameters.StochasticParameter, optional) – Maximum height and width in pixels of the low resolution plane. Upon any sampling call, the requested shape will be downscaled until the height or width (whichever is larger) does not exceed this maximum value anymore. Then the noise will be sampled at that shape and later upscaled back to the requested shape.

    • If a single int, this int will be used as a constant value.
    • If a tuple of two int s (a, b), the value will be sampled from the discrete interval [a..b] once per call.
    • If a list of int, a random value will be picked from the list once per call.
    • If a StochasticParameter, that parameter will be queried once per call.

    “per call” denotes a call of SimplexNoise.draw_sample() or SimplexNoise.draw_samples().

  • upscale_method (str or int or list of str or list of int or imgaug.parameters.StochasticParameter, optional) – After generating the noise maps in low resolution environments, they have to be upscaled to the originally requested shape (i.e. usually the image size). This parameter controls the interpolation method to use. See also imresize_many_images() for a description of possible values.

    • If imgaug.ALL, then either nearest or linear or area or cubic is picked per iteration (all same probability).
    • If str, then that value will always be used as the method (must be nearest or linear or area or cubic).
    • If list of str, then a random value will be picked from that list per call.
    • If StochasticParameter, then a random value will be sampled from that parameter per call.

Examples

>>> import imgaug.parameters as iap
>>> param = iap.SimplexNoise(upscale_method="linear")

Create a parameter that produces smooth simplex noise of varying sizes.

>>> param = iap.SimplexNoise(
>>>     size_px_max=(8, 16),
>>>     upscale_method="nearest")

Create a parameter that produces rectangular simplex noise of rather high detail.

Methods

copy(self) Create a shallow copy of this parameter.
deepcopy(self) Create a deep copy of this parameter.
draw_distribution_graph(self[, title, size, …]) Generate an image visualizing the parameter’s sample distribution.
draw_sample(self[, random_state]) Draws a single sample value from this parameter.
draw_samples(self, size[, random_state]) Draw one or more samples from the parameter.
class imgaug.parameters.StochasticParameter[source]

Bases: object

Abstract parent class for all stochastic parameters.

Stochastic parameters are here all parameters from which values are supposed to be sampled. Usually the sampled values are to a degree random. E.g. a stochastic parameter may be the uniform distribution over the interval [-10, 10]. Samples from that distribution (and therefore the stochastic parameter) could be 5.2, -3.7, -9.7, 6.4, etc.

Methods

copy(self) Create a shallow copy of this parameter.
deepcopy(self) Create a deep copy of this parameter.
draw_distribution_graph(self[, title, size, …]) Generate an image visualizing the parameter’s sample distribution.
draw_sample(self[, random_state]) Draws a single sample value from this parameter.
draw_samples(self, size[, random_state]) Draw one or more samples from the parameter.
copy(self)[source]

Create a shallow copy of this parameter.

Returns:Shallow copy.
Return type:imgaug.parameters.StochasticParameter
deepcopy(self)[source]

Create a deep copy of this parameter.

Returns:Deep copy.
Return type:imgaug.parameters.StochasticParameter
draw_distribution_graph(self, title=None, size=(1000, 1000), bins=100)[source]

Generate an image visualizing the parameter’s sample distribution.

Parameters:
  • title (None or False or str, optional) – Title of the plot. None is automatically replaced by a title derived from str(param). If set to False, no title will be shown.
  • size (tuple of int) – Number of points to sample. This is always expected to have at least two values. The first defines the number of sampling runs, the second (and further) dimensions define the size assigned to each draw_samples() call. E.g. (10, 20, 15) will lead to 10 calls of draw_samples(size=(20, 15)). The results will be merged to a single 1d array.
  • bins (int) – Number of bins in the plot histograms.
Returns:

data – Image of the plot.

Return type:

(H,W,3) ndarray

draw_sample(self, random_state=None)[source]

Draws a single sample value from this parameter.

Parameters: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) – A seed or random number generator to use during the sampling process. If None, the global RNG will be used. See also __init__() for a similar parameter with more details.
Returns:A single sample value.
Return type:any
draw_samples(self, size, random_state=None)[source]

Draw one or more samples from the parameter.

Parameters:
  • size (tuple of int or int) – Number of samples by dimension.
  • 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) – A seed or random number generator to use during the sampling process. If None, the global RNG will be used. See also __init__() for a similar parameter with more details.
Returns:

Sampled values. Usually a numpy ndarray of basically any dtype, though not strictly limited to numpy arrays. Its shape is expected to match size.

Return type:

ndarray

class imgaug.parameters.Subtract(other_param, val, elementwise=False)[source]

Bases: imgaug.parameters.StochasticParameter

Subtract from the samples of another stochastic parameter.

Parameters:
  • other_param (number or tuple of number or list of number or imgaug.parameters.StochasticParameter) – Samples of val will be subtracted from samples of this parameter. Let S be the requested shape of samples, then the datatype behaviour is as follows:

    • If a single number, this number will be used as a constant value to fill an array of shape S.
    • If a tuple of two number s (a, b), an array of shape S will be filled with uniformly sampled values from the continuous interval [a, b).
    • If a list of number, an array of shape S will be filled with randomly picked values from the list.
    • If a StochasticParameter, that parameter will be queried once per call to generate an array of shape S.

    “per call” denotes a call of Subtract.draw_sample() or Subtract.draw_samples().

  • val (number or tuple of number or list of number or imgaug.parameters.StochasticParameter) – Value to subtract from the other parameter. Datatype behaviour is analogous to other_param, though if elementwise=False (the default), only a single sample will be generated per call instead of S.

  • elementwise (bool, optional) – Controls the sampling behaviour of val. If set to False, a single samples will be requested from val and used as the constant multiplier. If set to True, samples of shape S will be requested from val and subtracted elementwise from the samples of other_param.

Examples

>>> import imgaug.parameters as iap
>>> param = iap.Subtract(iap.Uniform(0.0, 1.0), 1.0)

Convert a uniform distribution from [0.0, 1.0) to [-1.0, 0.0).

Methods

copy(self) Create a shallow copy of this parameter.
deepcopy(self) Create a deep copy of this parameter.
draw_distribution_graph(self[, title, size, …]) Generate an image visualizing the parameter’s sample distribution.
draw_sample(self[, random_state]) Draws a single sample value from this parameter.
draw_samples(self, size[, random_state]) Draw one or more samples from the parameter.
class imgaug.parameters.TruncatedNormal(loc, scale, low=-inf, high=inf)[source]

Bases: imgaug.parameters.StochasticParameter

Parameter that resembles a truncated normal distribution.

A truncated normal distribution is similar to a normal distribution, except the domain is smoothly bounded to a min and max value.

This is a wrapper around scipy.stats.truncnorm().

Parameters:
  • loc (number or tuple of number or list of number or imgaug.parameters.StochasticParameter) –

    The mean of the normal distribution.

    • If a single number, this number will be used as a constant value.
    • If a tuple of two number s (a, b), the value will be sampled from the continuous interval [a, b) once per call.
    • If a list of number, a random value will be picked from the list once per call.
    • If a StochasticParameter, that parameter will be queried once per call.

    “per call” denotes a call of TruncatedNormal.draw_sample() or TruncatedNormal.draw_samples().

  • scale (number or tuple of number or list of number or imgaug.parameters.StochasticParameter) – The standard deviation of the normal distribution. If this parameter reaches 0, the output array will be filled with loc. Datatype behaviour is the same as for loc.

  • low (number or tuple of number or list of number or imgaug.parameters.StochasticParameter) – The minimum value of the truncated normal distribution. Datatype behaviour is the same as for loc.

  • high (number or tuple of number or list of number or imgaug.parameters.StochasticParameter) – The maximum value of the truncated normal distribution. Datatype behaviour is the same as for loc.

Examples

>>> import imgaug.parameters as iap
>>> param = iap.TruncatedNormal(0, 5.0, low=-10, high=10)
>>> samples = param.draw_samples(100, random_state=0)
>>> assert np.all(samples >= -10)
>>> assert np.all(samples <= 10)

Create a truncated normal distribution with its minimum at -10.0 and its maximum at 10.0.

Methods

copy(self) Create a shallow copy of this parameter.
deepcopy(self) Create a deep copy of this parameter.
draw_distribution_graph(self[, title, size, …]) Generate an image visualizing the parameter’s sample distribution.
draw_sample(self[, random_state]) Draws a single sample value from this parameter.
draw_samples(self, size[, random_state]) Draw one or more samples from the parameter.
class imgaug.parameters.Uniform(a, b)[source]

Bases: imgaug.parameters.StochasticParameter

Parameter that resembles a uniform distribution over [a, b).

Parameters:
  • a (number or tuple of number or list of number or imgaug.parameters.StochasticParameter) – Lower bound of the interval. If a>b, a and b will automatically be flipped. If a==b, all generated values will be identical to a.

    • If a single number, this number will be used as a constant value.
    • If a tuple of two number s (a, b), the value will be sampled from the continuous interval [a, b) once per call.
    • If a list of number, a random value will be picked from the list once per call.
    • If a StochasticParameter, that parameter will be queried once per call.

    “per call” denotes a call of Uniform.draw_sample() or Uniform.draw_samples().

  • b (number or tuple of number or list of number or imgaug.parameters.StochasticParameter) – Upper bound of the interval. Analogous to a.

Examples

>>> import imgaug.parameters as iap
>>> param = iap.Uniform(0, 10.0)
>>> sample = param.draw_sample()
>>> assert 0 <= sample < 10.0

Create and sample from a uniform distribution over [0, 10.0).

Methods

copy(self) Create a shallow copy of this parameter.
deepcopy(self) Create a deep copy of this parameter.
draw_distribution_graph(self[, title, size, …]) Generate an image visualizing the parameter’s sample distribution.
draw_sample(self[, random_state]) Draws a single sample value from this parameter.
draw_samples(self, size[, random_state]) Draw one or more samples from the parameter.
class imgaug.parameters.Weibull(a)[source]

Bases: imgaug.parameters.StochasticParameter

Parameter that resembles a (continuous) weibull distribution.

This is a wrapper around numpy’s numpy.random.weibull().

Parameters:

a (number or tuple of number or list of number or imgaug.parameters.StochasticParameter) –

Shape parameter of the distribution.

  • If a single number, this number will be used as a constant value.
  • If a tuple of two number s (a, b), the value will be sampled from the continuous interval [a, b) once per call.
  • If a list of number, a random value will be picked from the list once per call.
  • If a StochasticParameter, that parameter will be queried once per call.

“per call” denotes a call of Weibull.draw_sample() or Weibull.draw_samples().

Examples

>>> import imgaug.parameters as iap
>>> param = iap.Weibull(a=0.5)

Create a weibull distribution with shape 0.5.

Methods

copy(self) Create a shallow copy of this parameter.
deepcopy(self) Create a deep copy of this parameter.
draw_distribution_graph(self[, title, size, …]) Generate an image visualizing the parameter’s sample distribution.
draw_sample(self[, random_state]) Draws a single sample value from this parameter.
draw_samples(self, size[, random_state]) Draw one or more samples from the parameter.
imgaug.parameters.both_np_float_if_one_is_float(a, b)[source]
imgaug.parameters.draw_distributions_grid(params, rows=None, cols=None, graph_sizes=(350, 350), sample_sizes=None, titles=None)[source]
imgaug.parameters.force_np_float_dtype(val)[source]
imgaug.parameters.handle_categorical_string_param(param, name, valid_values=None)[source]
imgaug.parameters.handle_continuous_param(param, name, value_range=None, tuple_to_uniform=True, list_to_choice=True)[source]
imgaug.parameters.handle_discrete_kernel_size_param(param, name, value_range=(1, None), allow_floats=True)[source]
imgaug.parameters.handle_discrete_param(param, name, value_range=None, tuple_to_uniform=True, list_to_choice=True, allow_floats=True)[source]
imgaug.parameters.handle_probability_param(param, name, tuple_to_uniform=False, list_to_choice=False)[source]
imgaug.parameters.show_distributions_grid(params, rows=None, cols=None, graph_sizes=(350, 350), sample_sizes=None, titles=None)[source]