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.StochasticParameterConvert 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.StochasticParameterAdd 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
Sbe the requested shape of samples, then the datatype behaviour is as follows:- If a single
number, thisnumberwill be used as a constant value to fill an array of shapeS. - If a
tupleof twonumbers(a, b), an array of shapeSwill be filled with uniformly sampled values from the continuous interval[a, b). - If a
listofnumber, an array of shapeSwill be filled with randomly picked values from thelist. - If a
StochasticParameter, that parameter will be queried once per call to generate an array of shapeS.
“per call” denotes a call of
Add.draw_sample()orAdd.draw_samples().- If a single
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 ofS.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 toTrue, samples of shapeSwill 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.StochasticParameterParameter 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 below0are automatically clipped to0+epsilon.- If a single
number, thisnumberwill be used as a constant value. - If a
tupleof twonumbers(a, b), the value will be sampled from the continuous interval[a, b)once per call. - If a
listofnumber, a random value will be picked from thelistonce per call. - If a
StochasticParameter, that parameter will be queried once per call.
“per call” denotes a call of
Beta.draw_sample()orBeta.draw_samples().- If a single
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 to0+epsilon.
Examples
>>> import imgaug.parameters as iap >>> param = iap.Beta(0.4, 0.6)
Create a beta distribution with
alpha=0.4andbeta=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.StochasticParameterBinomial 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, thisnumberwill be used as a constant value. - If a
tupleof twonumbers(a, b), the value will be sampled from the continuous interval[a, b)once per call. - If a
listofnumber, a random value will be picked from thelistonce per call. - If a
StochasticParameter, that parameter will be queried once per call.
“per call” denotes a call of
Binomial.draw_sample()orBinomial.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.01and0.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. - If a single
-
class
imgaug.parameters.ChiSquare(df)[source]¶ Bases:
imgaug.parameters.StochasticParameterParameter 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, thisintwill be used as a constant value. - If a
tupleof twoints(a, b), the value will be sampled from the discrete interval[a..b]once per call. - If a
listofint, a random value will be picked from thelistonce per call. - If a
StochasticParameter, that parameter will be queried once per call.
“per call” denotes a call of
ChiSquare.draw_sample()orChiSquare.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. - If a single
-
class
imgaug.parameters.Choice(a, replace=True, p=None)[source]¶ Bases:
imgaug.parameters.StochasticParameterParameter that samples value from a list of allowed values.
Parameters: - a (iterable) – List of allowed values.
Usually expected to be
ints,floats orstrs. May also containStochasticParameters. EachStochasticParameterthat is randomly picked will automatically be replaced by a sample of itself (or byNsamples if the parameter was pickedNtimes). - 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 sample17and in the other50%of all cases the sample5or25..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. - a (iterable) – List of allowed values.
Usually expected to be
-
class
imgaug.parameters.Clip(other_param, minval=None, maxval=None)[source]¶ Bases:
imgaug.parameters.StochasticParameterClip 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.0or above2.0. Note that this will lead to small “bumps” of higher probability at-2.0and2.0, as values below/above these will be clipped to them. For smoother limitations on gaussian distributions, seeTruncatedNormal.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.StochasticParameterParameter that is a constant value.
If
Nvalues are sampled from this parameter, it will returnNtimesV, whereVis 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.StochasticParameterParameter 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 firstA*B*Celements, reshaped to(A, B, C)from the provided list. If the list contains less thanA*B*Celements, 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.StochasticParameterUniform 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. Ifa==b, all generated values will be identical to a.- If a single
int, thisintwill be used as a constant value. - If a
tupleof twoints(a, b), the value will be sampled from the discrete interval[a..b]once per call. - If a
listofint, a random value will be picked from thelistonce per call. - If a
StochasticParameter, that parameter will be queried once per call.
“per call” denotes a call of
DiscreteUniform.draw_sample()orDiscreteUniform.draw_samples().- If a single
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.StochasticParameterConvert 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.StochasticParameterDivide 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
Sbe the requested shape of samples, then the datatype behaviour is as follows:- If a single
number, thisnumberwill be used as a constant value to fill an array of shapeS. - If a
tupleof twonumbers(a, b), an array of shapeSwill be filled with uniformly sampled values from the continuous interval[a, b). - If a
listofnumber, an array of shapeSwill be filled with randomly picked values from thelist. - If a
StochasticParameter, that parameter will be queried once per call to generate an array of shapeS.
“per call” denotes a call of
Divide.draw_sample()orDivide.draw_samples().- If a single
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 ofS.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 toTrue, samples of shapeSwill 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.StochasticParameterConvert 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
invertandreroll.invertmeans that wrong signs are simply flipped.rerollmeans 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 inmode="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=1that 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.StochasticParameterParameter 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 (around4.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) to4(small patterns). To generate cloud-like structures, use roughly-2.- If a single
number, thisnumberwill be used as a constant value. - If a
tupleof twonumbers(a, b), the value will be sampled from the continuous interval[a, b)once per call. - If a
listofnumber, a random value will be picked from thelistonce per call. - If a
StochasticParameter, that parameter will be queried once per call.
- If a single
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, thisintwill be used as a constant value. - If a
tupleof twoints(a, b), the value will be sampled from the discrete interval[a..b]once per call. - If a
listofint, a random value will be picked from thelistonce per call. - If a
StochasticParameter, that parameter will be queried once per call.
“per call” denotes a call of
FrequencyNoise.draw_sample()orFrequencyNoise.draw_samples().- If a single
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 eithernearestorlinearorareaorcubicis picked per iteration (all same probability). - If
str, then that value will always be used as the method (must benearestorlinearorareaorcubic). - If
listofstr, 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.
- If
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.StochasticParameterParameter 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*WwithHbeing the height andWbeing the width. After the low-resolution sampling this parameter then upscales the result toHxW.This parameter is intended to produce coarse samples. E.g. combining this with
Binomialcan lead to large rectangular areas of1s and0s.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 aStochasticParameter, which will be queried per call toFromLowerResolution.draw_sample()andFromLowerResolution.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 aStochasticParameter, which will be queried once per call toFromLowerResolution.draw_sample()andFromLowerResolution.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 inimresize_many_images(). Usuallynearestorlinearare good choices.nearestwill result in rectangles with sharp edges andlinearin rectangles with blurry and round edges. The method may be provided as aStochasticParameter, which will be queried once per call toFromLowerResolution.draw_sample()andFromLowerResolution.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 from2x2xCup to16x16xCmax, but may also be e.g.4x8xC). The upsampling method will benearestin50%of all cases andlinearin the other 50 percent. The result will sometimes be rectangular patches of sharp1s surrounded by0s and sometimes blurry blobs of1``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.StochasticParameterAggregate multiple iterations of samples from another parameter.
This is supposed to be used in conjunction with
SimplexNoiseorFrequencyNoise. If a shapeSis requested, it will requestItimesSsamples from the underlying parameter, whereIis the number of iterations. TheIarrays will be combined to a single array of shapeSusing 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, thisintwill be used as a constant value. - If a
tupleof twoints(a, b), the value will be sampled from the discrete interval[a..b]once per call. - If a
listofint, a random value will be picked from thelistonce per call. - If a
StochasticParameter, that parameter will be queried once per call.
“per call” denotes a call of
IterativeNoiseAggregator.draw_sample()orIterativeNoiseAggregator.draw_samples().- If a single
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
Seach to a single array of shapeSand hence work elementwise. Known methods aremin(take the minimum over all iterations),max(take the maximum) andavg(take the average).- If an
str, it must be one of the described methods and will be used for all calls.. - If a
listofstr, 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 thelist["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()orIterativeNoiseAggregator.draw_samples().- If an
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
2to5arrays 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.StochasticParameterParameter 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, thisnumberwill be used as a constant value. - If a
tupleof twonumbers(a, b), the value will be sampled from the continuous interval[a, b)once per call. - If a
listofnumber, a random value will be picked from thelistonce per call. - If a
StochasticParameter, that parameter will be queried once per call.
“per call” denotes a call of
Laplace.draw_sample()orLaplace.draw_samples().- If a single
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
0and decay is1.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.StochasticParameterMultiply 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
Sbe the requested shape of samples, then the datatype behaviour is as follows:- If a single
number, thisnumberwill be used as a constant value to fill an array of shapeS. - If a
tupleof twonumbers(a, b), an array of shapeSwill be filled with uniformly sampled values from the continuous interval[a, b). - If a
listofnumber, an array of shapeSwill be filled with randomly picked values from thelist. - If a
StochasticParameter, that parameter will be queried once per call to generate an array of shapeS.
“per call” denotes a call of
Multiply.draw_sample()orMultiply.draw_samples().- If a single
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 ofS.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 toTrue, samples of shapeSwill 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
invertandreroll.invertmeans that wrong signs are simply flipped.rerollmeans 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 inmode="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.StochasticParameterParameter 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, thisnumberwill be used as a constant value. - If a
tupleof twonumbers(a, b), the value will be sampled from the continuous interval[a, b)once per call. - If a
listofnumber, a random value will be picked from thelistonce per call. - If a
StochasticParameter, that parameter will be queried once per call.
“per call” denotes a call of
Laplace.draw_sample()orLaplace.draw_samples().- If a single
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 sometimesN(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.StochasticParameterParameter that resembles a poisson distribution.
A poisson distribution with
lambda=0has its highest probability at point0and 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, thisnumberwill be used as a constant value. - If a
tupleof twonumbers(a, b), the value will be sampled from the continuous interval[a, b)once per call. - If a
listofnumber, a random value will be picked from thelistonce per call. - If a
StochasticParameter, that parameter will be queried once per call.
“per call” denotes a call of
Poisson.draw_sample()orPoisson.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=1and 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. - If a single
-
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
invertandreroll.invertmeans that wrong signs are simply flipped.rerollmeans 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 inmode="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.StochasticParameterExponentiate 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
Sbe the requested shape of samples, then the datatype behaviour is as follows:- If a single
number, thisnumberwill be used as a constant value to fill an array of shapeS. - If a
tupleof twonumbers(a, b), an array of shapeSwill be filled with uniformly sampled values from the continuous interval[a, b). - If a
listofnumber, an array of shapeSwill be filled with randomly picked values from thelist. - If a
StochasticParameter, that parameter will be queried once per call to generate an array of shapeS.
“per call” denotes a call of
Power.draw_sample()orPower.draw_samples().- If a single
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 ofS.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 toTrue, samples of shapeSwill 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.StochasticParameterConvert 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=1that 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.StochasticParameterApply a sigmoid function to the outputs of another parameter.
This is intended to be used in combination with
SimplexNoiseorFrequencyNoise. It pushes the noise values away from~0.5and towards0.0or1.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.0to1.0.- If a single
number, thisnumberwill be used as a constant value. - If a
tupleof twonumbers(a, b), the value will be sampled from the continuous interval[a, b)once per call. - If a
listofnumber, a random value will be picked from thelistonce per call. - If a
StochasticParameter, that parameter will be queried once per call.
“per call” denotes a call of
Sigmoid.draw_sample()orSigmoid.draw_samples().- If a single
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 afloatpin value range``[0.0, 1.0]``, which will result in activated beingTrueinppercent 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 about20.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 to20.
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
SimplexNoiseandFrequencyNoise.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: - other_param (imgaug.parameters.StochasticParameter) – See
-
class
imgaug.parameters.SimplexNoise(size_px_max=(2, 16), upscale_method=['linear', 'nearest'])[source]¶ Bases:
imgaug.parameters.StochasticParameterParameter 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, thisintwill be used as a constant value. - If a
tupleof twoints(a, b), the value will be sampled from the discrete interval[a..b]once per call. - If a
listofint, a random value will be picked from thelistonce per call. - If a
StochasticParameter, that parameter will be queried once per call.
“per call” denotes a call of
SimplexNoise.draw_sample()orSimplexNoise.draw_samples().- If a single
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 eithernearestorlinearorareaorcubicis picked per iteration (all same probability). - If
str, then that value will always be used as the method (must benearestorlinearorareaorcubic). - If
listofstr, 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.
- If
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:
objectAbstract 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 be5.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.
Noneis automatically replaced by a title derived fromstr(param). If set toFalse, 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 to10calls ofdraw_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
- title (None or False or str, optional) – Title of the plot.
-
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.StochasticParameterSubtract 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
Sbe the requested shape of samples, then the datatype behaviour is as follows:- If a single
number, thisnumberwill be used as a constant value to fill an array of shapeS. - If a
tupleof twonumbers(a, b), an array of shapeSwill be filled with uniformly sampled values from the continuous interval[a, b). - If a
listofnumber, an array of shapeSwill be filled with randomly picked values from thelist. - If a
StochasticParameter, that parameter will be queried once per call to generate an array of shapeS.
“per call” denotes a call of
Subtract.draw_sample()orSubtract.draw_samples().- If a single
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 ofS.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 toTrue, samples of shapeSwill 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.StochasticParameterParameter 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, thisnumberwill be used as a constant value. - If a
tupleof twonumbers(a, b), the value will be sampled from the continuous interval[a, b)once per call. - If a
listofnumber, a random value will be picked from thelistonce per call. - If a
StochasticParameter, that parameter will be queried once per call.
“per call” denotes a call of
TruncatedNormal.draw_sample()orTruncatedNormal.draw_samples().- If a single
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.0and its maximum at10.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.StochasticParameterParameter 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. Ifa==b, all generated values will be identical to a.- If a single
number, thisnumberwill be used as a constant value. - If a
tupleof twonumbers(a, b), the value will be sampled from the continuous interval[a, b)once per call. - If a
listofnumber, a random value will be picked from thelistonce per call. - If a
StochasticParameter, that parameter will be queried once per call.
“per call” denotes a call of
Uniform.draw_sample()orUniform.draw_samples().- If a single
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.StochasticParameterParameter 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, thisnumberwill be used as a constant value. - If a
tupleof twonumbers(a, b), the value will be sampled from the continuous interval[a, b)once per call. - If a
listofnumber, a random value will be picked from thelistonce per call. - If a
StochasticParameter, that parameter will be queried once per call.
“per call” denotes a call of
Weibull.draw_sample()orWeibull.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. - If a single
-
imgaug.parameters.draw_distributions_grid(params, rows=None, cols=None, graph_sizes=(350, 350), sample_sizes=None, titles=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]¶