Imglib2 / ImageJ examples for the 2019 DAIS Learnathon.
Sample data for the Point rendering example can be downloaded here. Extract the contents of the zip file into this repositories resources
folder.
These examples show how to apply spatial transformations to points and images using imglib2.
Spatial transformations change an image by "moving the image" rather than affecting pixel values. A transform is a function with a point coordinate as an input, and another point coordinate as an output.
Discrete transformations have discrete valued inputs and outputs.
In compute-science terms, this means that the point coordinates
are stored as integer (int
/long
) valued variables.
We will call this set of discrete location the "image grid".
Discrete transforms can not accept points off the image grid,
nor can they produce
Continuous transformations have continous valued inputs and outputs.
In math language, the point coordinates are Real numbers.
In computer-science language, the point coordinates are represented by
floating-point (float
/double
) variables. Continuous transformations
can accept any points as inputs or outputs (on or between the image grid).
The function:
f(x,y) = ((x + 100), ( y - 0.5 ))
is a continuous transformation that translates the point (x,y)
100 units in the +x
direction, and -0.5 units in the +y direction.
g(i,j) = ((j), (-i))
is a discrete transformation that:
- Inverts the i axis
- Changes the roles of the i- and j-axes.
This example shows how to:
- Apply a simple translation to an image and display it
- Apply a complicated discrete transformation to an image and show it
- Highlights some common pitfalls.
Composition transformation is just like composing functions - the input of one transformation is the output of another.
See this Robert Haase tweet and the related discussion.
This example we will learn:
- That it is important to interpolate as little as possible.
- Why that is the case.
- That transformation composition is the solution.
Deformation fields are one of the most common representation of non-linear spatial transformations.
This example we will learn:
- What a displacement field is.
- How to construct a deformation field and warp an image with it.
- How to numerically invert a displacement field.
- Save your transforms to disk when transforming images.
- It's more important to save the transforms, than to save the images(!)
- Use and respect the image metadata
- Set pixel spacing and origin in physical units
- Define transforms in physical units (nm, um, mm, au, whatever) not pixels.
- This makes your life super easy when dealing with images of the same thing taken at different resolutions and/or with slightly different fields of view.
- Respect your origin
- Pick it, and stick with it.
- Don't define rotations about the center because it's convenient (now), it will cause pain (later).
- Imglib2 was the basis of everything here.
- imglib2-realtransform was the api used for continous transformations
- Scijava was used to
- The N5 api is used to: