Composition utilities
Aside from "true" operations that specify some kind of transformation, there are also a couple of special utility operations used for functionality such as stochastic branching.
using Augmentor
using Random
Random.seed!(1337)
img_in = testpattern(RGB, ratio=0.5)
img_out = augment(img_in, Either(0.5=>NoOp(), 0.25=>FlipX(), 0.25=>FlipY()))
References
Augmentor.NoOp
— TypeNoOp <: Augmentor.AffineOperation
Identity transformation that does not do anything with the given image, but instead passes it along unchanged (without copying).
Usually used in combination with Either
to denote a "branch" that does not perform any computation.
Augmentor.Either
— TypeEither <: Augmentor.ImageOperation
Description
Chooses between the given operations
at random when applied. This is particularly useful if one for example wants to first either rotate the image 90 degree clockwise or anticlockwise (but never both), and then apply some other operation(s) afterwards.
When compiling a pipeline, Either
will analyze the provided operations
in order to identify the preferred formalism to use when applied. The chosen formalism is chosen such that it is supported by all given operations
. This way the output of applying Either
will be inferable and the whole pipeline will remain type-stable (even though randomness is involved).
By default each specified image operation has the same probability of occurrence. This default behaviour can be overwritten by specifying the chance
manually.
Usage
Either(operations, [chances])
Either(operations...; [chances])
Either(pairs...)
*(operations...)
*(pairs...)
Arguments
operations
:NTuple
orVararg
ofAugmentor.ImageOperation
that denote the possible choices to sample from when applied.chances
: Optional. Denotes the relative chances for an operation to be sampled. Has to contain the same number of elements asoperations
. Either anNTuple
of numbers if specified as positional argument, or alternatively aAbstractVector
of numbers if specified as a keyword argument. If omitted every operation will have equal probability of occurring.pairs
:Vararg
ofPair{<:Real,<:Augmentor.ImageOperation}
. A compact way to specify an operation and its chance of occurring together.
See also
Examples
using Augmentor
img = testpattern()
# all three operations have equal chance of occuring
augment(img, Either(FlipX(), FlipY(), NoOp()))
augment(img, FlipX() * FlipY() * NoOp())
# NoOp is twice as likely as either FlipX or FlipY
augment(img, Either(1=>FlipX(), 1=>FlipY(), 2=>NoOp()))
augment(img, Either(FlipX(), FlipY(), NoOp(), chances=[1,1,2]))
augment(img, Either((FlipX(), FlipY(), NoOp()), (1,1,2)))
augment(img, (1=>FlipX()) * (1=>FlipY()) * (2=>NoOp()))
Augmentor.CacheImage
— TypeCacheImage <: Augmentor.ImageOperation
Description
Write the current state of the image into the working memory. Optionally a user has the option to specify a preallocated buffer
to write the image into. Note that if a buffer
is provided, then it has to be of the correct size and eltype.
Even without a preallocated buffer
it can be beneficial in some situations to cache the image. An example for such a scenario is when chaining a number of affine transformations after an elastic distortion, because performing that lazily requires nested interpolation.
Usage
CacheImage()
CacheImage(buffer)
Arguments
buffer
: Optional. A preallocatedAbstractArray
of the appropriate size and eltype.
See also
Examples
using Augmentor
# make pipeline that forces caching after elastic distortion
pl = ElasticDistortion(3,3) |> CacheImage() |> Rotate(-10:10) |> ShearX(-5:5)
# cache output of elastic distortion into the allocated
# 20x20 Matrix{Float64}. Note that for this case this assumes that
# the input image is also a 20x20 Matrix{Float64}
pl = ElasticDistortion(3,3) |> CacheImage(zeros(20,20)) |> Rotate(-10:10)
# convenience syntax with the same effect as above.
pl = ElasticDistortion(3,3) |> zeros(20,20) |> Rotate(-10:10)
This page was generated using DemoCards.jl and Literate.jl.