Scale (ome_zarr.scale)

Module for downsampling numpy arrays via various methods.

See the Scaler class for details.

class ome_zarr.scale.Methods(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Downsampling methods for multi-scale image generation.

Each method uses different algorithms and parameters. Refer to the method_dispatch dictionary for detailed configuration of each approach.

LOCAL_MEAN = 'local_mean'

Local mean downsampling.

Uses skimage.transform.downscale_local_mean() to average pixel values in fixed-size neighborhoods.

NEAREST = 'nearest'

Nearest-neighbor downsampling.

Uses skimage.transform.resize() with:

  • order=0 (nearest neighbor)

  • mode=’reflect’

  • anti_aliasing=False

  • preserve_range=True

RESIZE = 'resize'

Bilinear interpolation downsampling (default).

Uses skimage.transform.resize() with:

  • order=1 (bilinear interpolation)

  • mode=’reflect’

  • anti_aliasing=True

  • preserve_range=True

ZOOM = 'zoom'

Zoom-based flexible downsampling.

Uses scipy.ndimage.zoom() for general-purpose downsampling.

class ome_zarr.scale.Scaler(*args, **kwargs)[source]

Helper class for performing various types of downsampling.

Deprecated since version 0.14.0: This class is deprecated and should not be used.

Downsampling via the Scaler class has been deprecated. Please use the scale_factors argument in the ome_zarr.writer.write_image() function instead.

A method can be chosen by name such as “nearest”. All methods on this that do not begin with “_” and not either “methods” or “scale” are valid choices. These values can be returned by the methods() method.

copy_metadata

If True, copy Zarr attributes from the input array to the new group.

Type:

bool

downscale

Downscaling factor.

Type:

int

in_place

Does not do anything.

Type:

bool

labeled

If True, check that the values in the downsampled levels are a subset of the values found in the input array.

Type:

bool

max_layer

The maximum number of downsampled layers to create.

Type:

int

method

Downsampling method

Type:

str

>>> import numpy as np
>>> data = np.zeros((1, 1, 1, 64, 64))
>>> scaler = Scaler()
>>> downsampling = scaler.nearest(data)
>>> for x in downsampling:
...     print(x.shape)
(1, 1, 1, 64, 64)
(1, 1, 1, 32, 32)
(1, 1, 1, 16, 16)
(1, 1, 1, 8, 8)
(1, 1, 1, 4, 4)
property func: Callable[[ndarray], list[ndarray]]

Get downsample function.

gaussian(base: ndarray) list[ndarray][source]

Downsample using skimage.transform.pyramid_gaussian().

laplacian(base: ndarray) list[ndarray][source]

Downsample using skimage.transform.pyramid_laplacian().

local_mean(base: ndarray) list[ndarray][source]

Downsample using skimage.transform.downscale_local_mean().

static methods() Iterator[str][source]

Return the name of all methods which define a downsampling.

Any of the returned values can be used as the methods argument to the Scaler constructor

nearest(base: ndarray) list[ndarray][source]

Downsample using skimage.transform.resize().

resize_image(image: Array | ndarray) Array | ndarray[source]

Resize a numpy array OR a dask array to a smaller array (not pyramid)

scale(input_array: str, output_directory: str) None[source]

Perform downsampling to disk.

zoom(base: ndarray) list[ndarray][source]

Downsample using scipy.ndimage.zoom().