Skip to content

Block algorithms: type conversion and downsampling #97

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 20, 2023
Merged

Conversation

tpietzsch
Copy link
Member

This PR provides

  1. A framework for implementing block-processing algorithms that build off the 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 (type O) from values in a flattened primitive input array (type I).
    To avoid mistakes in unchecked casting of primitive array types, BlockProcessor should be typically wrapped in UnaryBlockOperator<S,T> where S and T are source and target ImgLib2 RealType corresponding to the respective I and O array types. UnaryBlockOperator can be chained using UnaryBlockOperator.andThen(...).

Block algorithms are intended to run single-threaded.
Multi-threading is achieved on a coarser level by using them in CellLoaders for CahcedCellImg and creating multiple cells in parallel.

  1. An operator to convert between common RealTypes (signed and unsigned, with and without clamping).
    This code is partially auto-generated using the bin/generate.groovy script lifted from scijava-ops.

  2. 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 of
factor ~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 for CellImg or PlanarImg inputs, where PrimitveBlocks has a larger impact.)

I will make PRs to BigStitcher and bigdataviewer-core when this is merged and released.

tpietzsch added 4 commits May 30, 2023 21:22
…ting between pixel types

The new package net.imglib2.algorithm.blocks contains algorithms that
operate on primitive arrays using the PrimitiveBlocks utility added in
imglib2 6.2.0.

The net.imglib2.algorithm.blocks root and .util packages contain helpers
to define and chain block operators and to use them for creating CellImgs.

The net.imglib2.algorithm.blocks.convert package contains a type conversion
operator to convert between (primitive arrays corresponding to) standard
ImgLib2 RealTypes.
The net.imglib2.algorithm.blocks.downsample package provides operators
for downsampling blocks of (primitive arrays corresponding to) standard
ImgLib2 RealTypes.

Downsampling is always factor of 2 (in one ore more dimensions).
There are versions for downsampling 2x2x2... blocks with half-pixel offset
and 3x3x3... blocks on pixel centers.
@tpietzsch tpietzsch changed the title Bock algorithms: type conversion and downsampling Block algorithms: type conversion and downsampling May 30, 2023
@tpietzsch tpietzsch merged commit ccbaf1a into master Jun 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant