DataAugmentation.AbstractArrayItem
— Typeabstract type AbstractArrayItem{N, T}
Abstract type for all [Item
]s that wrap an N
-dimensional array with element type T
.
DataAugmentation.AbstractItem
— Typeabstract type AbstractItem
Abstract supertype for all items. To implement items, subtype either Item
to create a new item or ItemWrapper
to wrap an existing item.
DataAugmentation.AdjustBrightness
— TypeAdjustBrightness(δ = 0.2)
AdjustBrightness(distribution)
Adjust the brightness of an image by a factor chosen uniformly from f ∈ [1-δ, 1+δ]
by multiplying each color channel by f
.
You can also pass any Distributions.Sampleable
from which the factor is selected.
Pixels are clamped to [0,1] unless clamp=false
is passed.
Example
{cell=AdjustBrightness}
using DataAugmentation, TestImages
item = Image(testimage("lighthouse"))
tfm = AdjustBrightness(0.2)
titems = [apply(tfm, item) for _ in 1:8]
showgrid(titems; ncol = 4, npad = 16)
DataAugmentation.AdjustContrast
— TypeAdjustContrast(factor = 0.2)
AdjustContrast(distribution)
Adjust the contrast of an image by a factor chosen uniformly from f ∈ [1-δ, 1+δ]
.
Pixels c
are transformed c + μ*(1-f)
where μ
is the mean color of the image.
You can also pass any Distributions.Sampleable
from which the factor is selected.
Pixels are clamped to [0,1] unless clamp=false
is passed.
Example
{cell=AdjustBrightness}
using DataAugmentation, TestImages
item = Image(testimage("lighthouse"))
tfm = AdjustContrast(0.2)
titems = [apply(tfm, item) for _ in 1:8]
showgrid(titems; ncol = 4, npad = 16)
DataAugmentation.ArrayItem
— TypeArrayItem(a)
An item that contains an array.
DataAugmentation.BoundingBox
— TypeBoundingBox(points, sz)
BoundingBox{N, T, M}(points, bounds)
Item wrapper around Keypoints
.
Examples
{cell=BoundingBox}
using DataAugmentation, StaticArrays
points = [SVector(10., 10.), SVector(80., 60.)]
item = BoundingBox(points, (100, 100))
{cell=BoundingBox}
showitems(item)
DataAugmentation.Categorify
— TypeCategorify(dict, cols)
Label encodes the values of a row present in TabularItem
for the columns specified in cols
using dict
, which contains the column names as dictionary keys and the unique values of column present as dictionary values.
if there are any missing
values in the values to be transformed, they are replaced by 1.
Example
using DataAugmentation
cols = [:col1, :col2, :col3]
row = (; zip(cols, ["cat", 2, 3])...)
item = TabularItem(row, cols)
catdict = Dict(:col1 => ["dog", "cat"])
tfm = Categorify(catdict, [:col1])
apply(tfm, item)
DataAugmentation.ComposedProjectiveTransform
— TypeComposedProjectiveTransform(tfms...)
Wrap multiple projective tfms
and apply them efficiently. The projections are fused into a single projection and only points inside the final crop are evaluated.
DataAugmentation.FillMissing
— TypeFillMissing(dict, cols)
Fills the missing values of a row present in TabularItem
for the columns specified in cols
using dict
, which contains the column names as dictionary keys and the value to fill the column with present as dictionary values.
Example
using DataAugmentation
cols = [:col1, :col2, :col3]
row = (; zip(cols, [1, 2, 3])...)
item = TabularItem(row, cols)
fmdict = Dict(:col1 => 100, :col2 => 100)
tfm = FillMissing(fmdict, [:col1, :col2])
apply(tfm, item)
DataAugmentation.Identity
— TypeIdentity()
The identity transformation.
DataAugmentation.Image
— TypeImage(image[, bounds])
Item representing an N-dimensional image with element type T.
Examples
{cell=image}
using DataAugmentation, Images
imagedata = rand(RGB, 100, 100)
item = Image(imagedata)
showitems(item)
If T
is not a color, the image will be interpreted as grayscale:
{cell=image}
imagedata = rand(Float32, 100, 100)
item = Image(imagedata)
showitems(item)
DataAugmentation.ImageToTensor
— TypeImageToTensor()
Expands an Image{N, T}
of size sz
to an ArrayItem{N+1}
with size (sz..., ch)
where ch
is the number of color channels of T
.
Supports apply!
.
Examples
{cell=ImageToTensor}
using DataAugmentation, Images
image = Image(rand(RGB, 50, 50))
tfm = ImageToTensor()
apply(tfm, image)
DataAugmentation.Item
— Typeabstract type Item
Abstract supertype of concrete items.
Subtype if you want to create a new item. If you want to wrap an existing item, see ItemWrapper
.
DataAugmentation.ItemWrapper
— Typeabstract type ItemWrapper{Item}
DataAugmentation.Keypoints
— TypeKeypoints(points, sz)
Keypoints{N, T, M}(points, bounds)
N
-dimensional keypoints represented as SVector{N, T}
.
Spatial bounds are given by the polygon bounds::Vector{SVector{N, T}}
or sz::NTuple{N, Int}
.
Examples
{cell=Keypoints}
using DataAugmentation, StaticArrays
points = [SVector(y, x) for (y, x) in zip(4:5:80, 10:6:90)]
item = Keypoints(points, (100, 100))
{cell=Keypoints}
showitems(item)
DataAugmentation.MapElem
— TypeMapElem(f)
Applies f
to every element in an [AbstractArrayItem
].
DataAugmentation.MaskBinary
— TypeMaskBinary(a)
An N
-dimensional binary mask.
Examples
{cell=MaskMulti}
using DataAugmentation
mask = MaskBinary(rand(Bool, 100, 100))
{cell=MaskMulti}
showitems(mask)
DataAugmentation.MaskMulti
— TypeMaskMulti(a, [classes])
An N
-dimensional multilabel mask with labels classes
.
Examples
{cell=MaskMulti}
using DataAugmentation
mask = MaskMulti(rand(1:3, 100, 100))
{cell=MaskMulti}
showitems(mask)
DataAugmentation.Normalize
— TypeNormalize(means, stds)
Normalizes the last dimension of an AbstractArrayItem{N}
.
Supports apply!
.
Examples
Preprocessing a 3D image with 3 color channels.
{cell=Normalize}
using DataAugmentation, Images
image = Image(rand(RGB, 20, 20, 20))
tfms = ImageToTensor() |> Normalize((0.1, -0.2, -0.1), (1,1,1.))
apply(tfms, image)
DataAugmentation.NormalizeRow
— TypeNormalizeRow(dict, cols)
Normalizes the values of a row present in TabularItem
for the columns specified in cols
using dict
, which contains the column names as dictionary keys and the mean and standard deviation tuple present as dictionary values.
Example
using DataAugmentation
cols = [:col1, :col2, :col3]
row = (; zip(cols, [1, 2, 3])...)
item = TabularItem(row, cols)
normdict = Dict(:col1 => (1, 1), :col2 => (2, 2))
tfm = NormalizeRow(normdict, [:col1, :col2])
apply(tfm, item)
DataAugmentation.OneHot
— TypeOneHot([T = Float32])
One-hot encodes a MaskMulti
with n
classes and size sz
into an array item of size (sz..., n)
with element type T
. Supports apply!
.
item = MaskMulti(rand(1:4, 100, 100), 1:4)
apply(OneHot(), item)
DataAugmentation.OneOf
— TypeOneOf(tfms)
OneOf(tfms, ps)
Apply one of tfms
selected randomly with probability ps
each or uniformly chosen if no ps
is given.
DataAugmentation.PinOrigin
— TypePinOrigin()
Projective transformation that translates the data so that the upper left bounding corner is at the origin (0, 0)
(or the multidimensional equivalent).
Projective transformations on images return OffsetArray
s, but not on keypoints. Hardware like GPUs do not support OffsetArrays, so they will be unwrapped and no longer match up with the keypoints.
Pinning the data to the origin makes sure that the resulting OffsetArray
has the same indices as a regular array, starting at one.
DataAugmentation.Polygon
— TypePolygon(points, sz)
Polygon{N, T, M}(points, bounds)
Item wrapper around Keypoints
.
Examples
{cell=Polygon}
using DataAugmentation, StaticArrays
points = [SVector(10., 10.), SVector(80., 20.), SVector(90., 70.), SVector(20., 90.)]
item = Polygon(points, (100, 100))
{cell=Polygon}
showitems(item)
DataAugmentation.ProjectiveTransform
— Typeabstract type ProjectiveTransform <: Transform
Abstract supertype for projective transformations. See Projective transformations.
DataAugmentation.Reflect
— TypeReflect(γ)
Reflect(distribution)
Reflect 2D spatial data around the center by an angle chosen at uniformly from [-γ, γ], an angle given in degrees.
You can also pass any Distributions.Sampleable
from which the angle is selected.
Examples
tfm = Reflect(10)
DataAugmentation.Rotate
— TypeRotate(γ)
Rotate(γs)
Rotate 2D spatial data around the center by an angle chosen at uniformly from [-γ, γ], an angle given in degrees.
You can also pass any Distributions.Sampleable
from which the angle is selected.
Examples
tfm = Rotate(10)
DataAugmentation.ScaleFixed
— TypeScaleFixed(sizes)
Projective transformation that scales sides to sizes
, disregarding aspect ratio.
See also ScaleKeepAspect
.
DataAugmentation.ScaleKeepAspect
— TypeScaleKeepAspect(minlengths) <: ProjectiveTransform
Scales the shortest side of item
to minlengths
, keeping the original aspect ratio.
Examples
{cell=ScaleKeepAspect}
using DataAugmentation, TestImages
image = testimage("lighthouse")
tfm = ScaleKeepAspect((200, 200))
apply(tfm, Image(image)) |> showitems
DataAugmentation.Sequence
— TypeSequence(transforms...)
Transform
that applies multiple transformations
after each other.
You should not use this explicitly. Instead use compose
.
DataAugmentation.ToEltype
— TypeToEltype(T)
Converts any AbstractArrayItem
to an AbstractArrayItem{N, T}
.
Supports apply!
.
Examples
{cell=ToEltype}
using DataAugmentation
tfm = ToEltype(Float32)
item = ArrayItem(rand(Int, 10))
apply(tfm, item)
DataAugmentation.Transform
— Typeabstract type Transform
Abstract supertype for all transformations.
DataAugmentation.WarpAffine
— TypeWarpAffine(σ = 0.1) <: ProjectiveTransform
A three-point affine warp calculated by randomly moving 3 corners of an item. Similar to a random translation, shear and rotation.
DataAugmentation.Zoom
— TypeZoom(scales = (1, 1.2)) <: ProjectiveTransform
Zoom(distribution)
Zoom into an item by a factor chosen from the interval scales
or distribution
.
DataAugmentation.Maybe
— FunctionMaybe(tfm, p = 0.5) <: Transform
With probability p
, apply transformation tfm
.
DataAugmentation.apply!
— Methodapply!(buffer::I, tfm, item::I)
Applies tfm
to item
, mutating the preallocated buffer
.
buffer
can be obtained with buffer = makebuffer(tfm, item)
apply!(buffer, tfm::Transform, item::I; randstate) = apply(tfm, item; randstate)
Default to apply(tfm, item)
(non-mutating version).
DataAugmentation.apply
— Methodapply(tfm, item[; randstate])
apply(tfm, items[; randstate])
Apply tfm
to an item
or a tuple items
.
DataAugmentation.boundsof
— Methodboundingranges(ps)
Find bounding index ranges for points ps
.
DataAugmentation.centered
— Methodcentered(P, bounds)
Transform P
so that is applied around the center of bounds
instead of the origin
DataAugmentation.compose
— Functioncompose(transforms...)
Compose tranformations. Use |>
as an alias.
Defaults to creating a Sequence
of transformations, but smarter behavior can be implemented. For example, MapElem(f) |> MapElem(g) == MapElem(g ∘ f)
.
DataAugmentation.getbounds
— Functiongetbounds(item)
Return the spatial bounds of item
. For a 2D-image (Image{2}
) the bounds are the 4 corners of the bounding rectangle. In general, for an N-dimensional item, the bounds are a vector of the N^2 corners of the N-dimensional hypercube bounding the data.
DataAugmentation.getprojection
— Functiongetprojection(tfm, bounds; randstate)
Create a projection for an item with spatial bounds bounds
. The projection should be a CoordinateTransformations.Transformation
. See CoordinateTransformations.jl
DataAugmentation.getrandstate
— Methodgetrandstate(transform)
Generates random state for stochastic transformations. Calling apply(tfm, item)
is equivalent to apply(tfm, item; randstate = getrandstate(tfm))
. It defaults to nothing
, so you it only needs to be implemented for stochastic Transform
s.
DataAugmentation.itemdata
— Methoditemdata(item)
itemdata(items)
Access the data wrapped in item
or a tuple of items.
DataAugmentation.makebuffer
— Methodmakebuffer(tfm, item)
Create a buffer buf
that can be used in a call to apply!(buf, tfm, item)
. Default to buffer = apply(tfm, item)
.
You only need to implement this if the default apply(tfm, item)
isn't enough. See apply(tfm::Sequence, item)
for an example of this.
DataAugmentation.offsetcropbounds
— Methodoffsetcropbounds(sz, bounds, offsets)
Calculate offset bounds for a crop of size sz
.
For every dimension i where sz[i] < length(indices[i])
, offsets the crop by offsets[i]
times the difference between the two.
DataAugmentation.project
— Functionproject(P, item, indices)
Project item
using projection P
and crop to indices
if given.
DataAugmentation.project!
— Methodproject!(bufitem, P, item, indices)
Project item
using projection P
and crop to indices
if given. Store result in bufitem
. Inplace version of project
.
Default implementation falls back to project
.
DataAugmentation.projectionbounds
— Methodprojectionbounds(tfm, P, bounds, randstate)
DataAugmentation.showitem!
— Functionshowitem!(item)
Visualize item
. Should return an image.
DataAugmentation.showitems
— Methodshowitems(items)
Visualize items
.
DataAugmentation.testapply!
— Methodtestapply!(tfm, Items)
testapply!(tfm, Item)
testapply!(tfm, item1, item2)
Test apply!
invariants.
- With a constant
randstate
parameter,apply!
should always return the same result. - Given a different item than was used to create the buffer, the buffer's data should be modified.
DataAugmentation.testapply
— Methodtestapply(tfm, item)
testapply(tfm, I)
Test apply
invariants of tfm
on item
or item type I
.
- With a constant
randstate
parameter,apply
should always return the same result.
DataAugmentation.testitem
— Functiontestitem(TItem)
Create an instance of an item with type TItem
. If it has spatial bounds, should return an instance with bounds with ranges (1:16, 1:16).
DataAugmentation.testprojective
— Methodtestprojective(tfm)
Test invariants of a ProjectiveTransform
.
getprojection
is defined, and, given a constantrandstate
parameter, always returns the same result.- It preserves the item type, i.e.
apply(tfm, ::I) -> I
. - Applying it to multiple items with the same bounds results in the same bounds for all items.
DataAugmentation.threepointwarpaffine
— Methodthreepointwarpaffine(srcps, dstps)
Calculate an affine CoordinateTransformations.LinearMap
from 3 source points to 3 destination points.
Adapted from CoordinateTransformations.jl#30.
DataAugmentation.transformbounds
— Methodtransformbounds(bounds, P)
Apply CoordinateTransformations.Transformation
to bounds
.