neuroglancer_scripts.downscaling module

Downscaling is used to create a multi-resolution image pyramid.

The central component here is the Downscaler base class. Use get_downscaler() for instantiating a concrete downscaler object.

class neuroglancer_scripts.downscaling.AveragingDownscaler(outside_value=None)[source]

Bases: Downscaler

Downscale by a factor of two in any given direction, with averaging.

This downscaler is suitable for grey-level images.

Todo

Use code from the neuroglancer module to support arbitrary factors.

check_factors(downscaling_factors)[source]

Test support for given downscaling factors.

Subclasses must override this method if they do not support any combination of integer downscaling factors.

Parameters:

downscaling_factors (tuple of int) – sequence of integer downscaling factors (Dx, Dy, Dz)

Returns:

whether the provided downscaling factors are supported

Return type:

bool

downscale(chunk, downscaling_factors)[source]

Downscale a chunk according to the provided factors.

Parameters:
  • chunk (numpy.ndarray) – chunk with (C, Z, Y, X) indexing

  • downscaling_factors (tuple) – sequence of integer downscaling factors (Dx, Dy, Dz)

Returns:

the downscaled chunk, with shape (C, ceil_div(Z, Dz), ceil_div(Y, Dy), ceil_div(X, Dx))

Return type:

numpy.ndarray

Raises:

NotImplementedError – if the downscaling factors are unsupported

class neuroglancer_scripts.downscaling.Downscaler[source]

Bases: object

Base class for downscaling algorithms.

check_factors(downscaling_factors)[source]

Test support for given downscaling factors.

Subclasses must override this method if they do not support any combination of integer downscaling factors.

Parameters:

downscaling_factors (tuple of int) – sequence of integer downscaling factors (Dx, Dy, Dz)

Returns:

whether the provided downscaling factors are supported

Return type:

bool

downscale(chunk, downscaling_factors)[source]

Downscale a chunk according to the provided factors.

Parameters:
  • chunk (numpy.ndarray) – chunk with (C, Z, Y, X) indexing

  • downscaling_factors (tuple) – sequence of integer downscaling factors (Dx, Dy, Dz)

Returns:

the downscaled chunk, with shape (C, ceil_div(Z, Dz), ceil_div(Y, Dy), ceil_div(X, Dx))

Return type:

numpy.ndarray

Raises:

NotImplementedError – if the downscaling factors are unsupported

class neuroglancer_scripts.downscaling.MajorityDownscaler[source]

Bases: Downscaler

Downscaler using majority voting.

This downscaler is suitable for label images.

Todo

The majority downscaler could be really optimized (clever iteration with nditer, Cython, countless for appropriate cases)

downscale(chunk, downscaling_factors)[source]

Downscale a chunk according to the provided factors.

Parameters:
  • chunk (numpy.ndarray) – chunk with (C, Z, Y, X) indexing

  • downscaling_factors (tuple) – sequence of integer downscaling factors (Dx, Dy, Dz)

Returns:

the downscaled chunk, with shape (C, ceil_div(Z, Dz), ceil_div(Y, Dy), ceil_div(X, Dx))

Return type:

numpy.ndarray

Raises:

NotImplementedError – if the downscaling factors are unsupported

class neuroglancer_scripts.downscaling.StridingDownscaler[source]

Bases: Downscaler

Downscale using striding.

This is a fast, low-quality downscaler that provides no protection against aliasing artefacts. It supports arbitrary downscaling factors.

downscale(chunk, downscaling_factors)[source]

Downscale a chunk according to the provided factors.

Parameters:
  • chunk (numpy.ndarray) – chunk with (C, Z, Y, X) indexing

  • downscaling_factors (tuple) – sequence of integer downscaling factors (Dx, Dy, Dz)

Returns:

the downscaled chunk, with shape (C, ceil_div(Z, Dz), ceil_div(Y, Dy), ceil_div(X, Dx))

Return type:

numpy.ndarray

Raises:

NotImplementedError – if the downscaling factors are unsupported

neuroglancer_scripts.downscaling.add_argparse_options(parser)[source]

Add command-line options for downscaling.

Parameters:

parser (argparse.ArgumentParser) – an argument parser

The downscaling options can be obtained from command-line arguments with add_argparse_options() and passed to get_downscaler():

import argparse
parser = argparse.ArgumentParser()
add_argparse_options(parser)
args = parser.parse_args()
get_downscaler(args.downscaling_method, vars(args))
neuroglancer_scripts.downscaling.get_downscaler(downscaling_method, info=None, options={})[source]

Create a downscaler object.

Parameters:
  • downscaling_method (str) – one of "average", "majority", or "stride"

  • options (dict) – options passed to the downscaler as kwargs.

Returns:

an instance of a sub-class of Downscaler

Return type:

Downscaler