AbstractMultiscaleTransforms.jl: Contourlets.jl, Surfacelets.jl, Shearlets.jl

I wanted to experiment with directional multiscale transforms, so I created my own implementations. I haven’t released them yet (except for Contourlets.jl) because I wanted to ask for some opinions on AbstractMultiscaleTransforms. The goal of this package is to have a unified interface for all multiscale transforms, potentially beyond the three mentioned ones (e.g. Wavelets.jl).

The Proposed Interface

x = randn(256, 256)
t = BandlimitedShearlets(scales = 3)  # transform: parameters only
c = analyze(t, x)                     # coefficients: an AbstractArray
b = subband(t, c, 2)                  # view of subband 2 (subband 1 is the lowpass)
synthesize(t, c) ≈ x                  # true

ws = make_workspace(t, x)             # precomputed plans/buffers for this size and eltype
analyze!(c, ws, x)                    # repeated calls allocate little or nothing

Defined Types

  • Transform (<: AbstractMultiscaleTransform): an immutable value that holds every parameter (scales, directions, filters) and nothing that depends on the data’s size or element type. One transform therefore works for any admissible size. Transforms with equal parameters return “true” for ==.

  • Workspace (<: AbstractTransformWorkspace, produced by make_workspace(t, x) or make_workspace(t, T, dims)): holds FFT plans, filter responses and scratch buffers for one size, element type and array type (CPU or GPU).

    • Every function, where applicable, accepts the “workspace” keyword, and a workspace can also stand in for its transform (e.g. analyze(ws, x)). A transform that precomputes nothing still returns a DefaultWorkspace, so generic code never has to branch.
  • Coefficients: always an AbstractArray, so generic code can broadcast over them and call norm, dot, axpy! and so on. They come in three layouts:

    • packed into an array of the same size as x for critically sampled separable transforms, like currently 2D and 3D dwt outputs in Wavelets.jl,
    • stacked, when all subbands have the same size as the input (nonsubsampled transforms): an array of size (size(x)..., n);
    • SubbandVector, when subband sizes differ (decimated transforms): all subbands flattened, packed one after another into a single vector, with some helpers to get correctly sized views. Element-wise arithmetic can operate directly on the storage vector.

The functions

  • analyze(t, x), analyze!(c, t, x): forward transform
  • synthesize(t, c), synthesize!(x, t, c): inverse transform
  • make_workspace: create a workspace
  • transform(ws): “extracts” the transform object from a workspace
  • similar_coefficients(t, x): allocates uninitialized storage for the output of analyze!
  • subband, nsubbands, subband_layout: helpers for subband access
  • analyze(f, t, x), synthesize!(f, x, t): optional streaming: f(i, band) is called per subband instead of storing all coefficients

Conventions

  • synthesize inverts analyze. It is the adjoint only for Parseval frames, and each package documents which of its transforms are Parseval frames.
  • Complex data is transformed as its real and imaginary parts, so analyze(t, x + im * y) ≈ analyze(t, x) + im * analyze(t, y).
  • analyze, synthesize (and their in-place variants) accept threaded = nothing | true | false.
  • Invalid input throws DimensionMismatch or ArgumentError before any work is done.

The proposed API can be studied in more detail on GitHub: GitHub - hakkelt/AbstractMultiscaleTransforms.jl: Abstract interface for multiscale transforms in Julia · GitHub

My Questions

  • What other transforms might fit under this API? What would be a suitable scope?
  • Is this a good name (that’s a thing I cannot change after registration, so that question always makes me nervous about whether I’ll regret the choice later…)?
  • Are there any suggestions to improve the proposed API or to broaden its scope? I’m still not fully convinced whether “analyze/synthesize” and “workspace” are the best choices. Also I considered ArrayPartition from RecursiveArrayTools.jl, but it might not be worth adding a heavy dependency.

Notes

Nice. I will try to find some time to take a look.