Higher-order functions

Source code notebook

These operations are useful to perform an operation that is not explicitly defined in Augmentor.

using Augmentor
using Random
using Statistics: mean

Random.seed!(1337)

DecreaseContrast = MapFun(pixel -> pixel / 2)
IncreaseBrightness = AggregateThenMapFun(img -> mean(img),
                                         (pixel, M) -> pixel + M / 5)

img_in = testpattern(RGB, ratio=0.5)
img_out = augment(img_in, DecreaseContrast |> IncreaseBrightness)

References

Augmentor.MapFun โ€” Type
MapFun <: Augmentor.Operation

Description

Maps the given function over all individual array elements.

This means that the given function is called with an individual elements and is expected to return a transformed element that should take the original's place. This further implies that the function is expected to be unary. It is encouraged that the function should be consistent with its return type and type-stable.

Usage

MapFun(fun)

Arguments

  • fun : The unary function that should be mapped over all individual array elements.

See also

AggregateThenMapFun, ConvertEltype, augment

Examples

using Augmentor, ColorTypes
img = testpattern()

# subtract the constant RGBA value from each pixel
augment(img, MapFun(px -> px - RGBA(0.5, 0.3, 0.7, 0.0)))

# separate channels to scale each numeric element by a constant value
pl = SplitChannels() |> MapFun(el -> el * 0.5) |> CombineChannels(RGBA)
augment(img, pl)
source
Augmentor.AggregateThenMapFun โ€” Type
AggregateThenMapFun <: Augmentor.Operation

Description

Compute some aggregated value of the current image using the given function aggfun, and map that value over the current image using the given function mapfun.

This is particularly useful for achieving effects such as per-image normalization.

Usage

AggregateThenMapFun(aggfun, mapfun)

Arguments

  • aggfun : A function that takes the whole current image as input and which result will also be passed to mapfun. It should have a signature of img -> agg, where img will the the current image. What type and value agg should be is up to the user.

  • mapfun : The binary function that should be mapped over all individual array elements. It should have a signature of (px, agg) -> new_px where px is a single element of the current image, and agg is the output of aggfun.

See also

MapFun, ConvertEltype, augment

Examples

using Augmentor
img = testpattern()

# subtract the average RGB value of the current image
augment(img, AggregateThenMapFun(img -> mean(img), (px, agg) -> px - agg))
source

This page was generated using DemoCards.jl and Literate.jl.