Block algorithms: type conversion and downsampling #97
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR provides
PrimitiveBlocks
utility introduced in imglib2 6.2.0.Package
net.imglib2.algorithm.block
contains helpers to define and chain block operators.In particular, the
BlockProcessor<I,O>
interface specifies an algorithm that computes values in a flattened primitive output array (typeO
) from values in a flattened primitive input array (typeI
).To avoid mistakes in unchecked casting of primitive array types,
BlockProcessor
should be typically wrapped inUnaryBlockOperator<S,T>
whereS
andT
are source and target ImgLib2 RealType corresponding to the respectiveI
andO
array types.UnaryBlockOperator
can be chained usingUnaryBlockOperator.andThen(...)
.Block algorithms are intended to run single-threaded.
Multi-threading is achieved on a coarser level by using them in
CellLoaders
forCahcedCellImg
and creating multiple cells in parallel.An operator to convert between common
RealType
s (signed and unsigned, with and without clamping).This code is partially auto-generated using the
bin/generate.groovy
script lifted from scijava-ops.An operator to downsample, by factor 2, blocks of common
RealType
.It can be specified whether intermediate calculations should happen in FLOAT or DOUBLE precision (or AUTOmatically determined). There are versions for downsampling 2x2x2... blocks with half-pixel offset and 3x3x3... blocks on pixel centers.
Together with
PrimitiveBlocks
from imglib2 core, the downsampling algorithm achieves speedup offactor ~4 over the downsampling used in bigdataviewer-core, and speedup of factor ~10 to ~30 over the downsampling used in BigStitcher (depending on Java version, block size, etc).
(This is on
ArrayImg
inputs. Speedups are probably even larger forCellImg
orPlanarImg
inputs, wherePrimitveBlocks
has a larger impact.)I will make PRs to BigStitcher and bigdataviewer-core when this is merged and released.