User guide (TODO)

Library

Projective transformations

Preprocessing

Reference

Transformation interface

base.jl

The transformation interface is the centrepiece of this library. Beside straightforward transform application it also enables stochasticity, composition and buffering.

A transformation is a type that subtypes Transform. The only required function to implement for your transformation type T is

You may additionally also implement:

Example

The implementation of the MapElem transformation illustrates this interface well. It transforms any item with array data by mapping a function over the array’s elements, just like Base.map.

struct MapElem <: Transform
    f
end

The apply implementation dispatches on AbstractArrayItem, an abstract item type for items that wrap arrays. Note that the randstate keyword argument needs to be given even for implementations of deterministic transformations. We also make use of the setdata helper to update the item data.

function apply(tfm::MapElem, item::AbstractArrayItem; randstate = nothing)
    a = itemdata(item)
    a_ = map(tfm.f, a)
    return setdata(item, a_)
end

The buffered version applies the function inplace using Base.map!:

function apply!(
        bufitem::I,
        tfm::MapElem,
        item::I;
        randstate = nothing) where I <: AbstractArrayItem
    map!(tfm.f, itemdata(bufitem), itemdata(item))
    return bufitem
end

Finally, a MapElem can also be composed nicely with other MapElems. Instead of applying them sequentially, the functions are fused and applied once.

compose(tfm1::MapElem, tfm2::MapElem2) = MapElem(tfm2.f ∘ tfm1.f)