cvpl_tools/im/algs

This subdirectory defines relevant algorithms for parallel processing of nd-images.

APIs

async cvpl_tools.im.algs.dask_label.label(im: ndarray[tuple[int, ...], dtype[_ScalarType_co]] | Array | NDBlock, output_dtype: dtype = None, context_args: dict = None) ndarray[tuple[int, ...], dtype[_ScalarType_co]] | Array | NDBlock

Dask array version of scipy.ndimage.label

Parameters:
  • im – The image to be labeled

  • output_dtype – Output label data type; choose one you will be sure to accommodate the max number of contours found in the image

  • context_args – extra contextual arguments - cache_url (str | RDirFileSystem): Points to directory under which cache will be stored - logging (bool, optional): If provided and True, print some debugging info to coiled logger

Returns:

Tuple (lbl_im, nlbl) where lbl_im is a globally labeled image of the same type/chunk size as the input

cvpl_tools.im.algs.dask_ndinterp.scale_nearest(image: Array, scale: float | tuple[float, ...], output_shape: tuple[int, ...], output_chunks: tuple[int, ...] = None, **kwargs) Array

Scaling the image without interpolation (order=0)

Note this function may cause a noticeable positional shift when scaling down

Parameters:
  • image – The image to be scaled by the given factor

  • scale – The scale to be applied to each axis; if float

  • output_shape – Shape of the output array

  • output_chunks – Shape of the chunks of the output array

  • **kwargs – arguments to be passed to affine_transform_nearest

Returns:

Scaled dask array

cvpl_tools.im.algs.dask_ndinterp.affine_transform_nearest(image: Array, matrix, output_shape: tuple[int, ...] = None, output_chunks: tuple[int, ...] = None, **kwargs) Array

Apply an affine transform using Dask. For every output chunk, only the slice containing the relevant part of the image is processed. Chunkwise processing is performed either using ndimage.affine_transform or cupyx.scipy.ndimage.affine_transform, depending on the input type.

Position of each voxel in input and output is assumed to be the center of the cube e.g. for 3d this is (x + .5, y + .5, z + .5), note that this is different from scipy’s affine_transform where the position is (x, y, z)

Notes

Differences to ndimage.affine_transformation: - modes ‘reflect’, ‘mirror’ and ‘wrap’ are not supported

Arguments equal to ndimage.affine_transformation, except for output_chunks.

Parameters:
  • image (array_like (Numpy Array, Cupy Array, Dask Array...)) – The image array.

  • matrix (array (ndim, ndim+1) or (ndim+1, ndim+1)) – Transformation matrix.

  • output_shape (tuple of ints, optional) – The shape of the array to be returned.

  • output_chunks (tuple of ints, optional) – The shape of the chunks of the output Dask Array.

Returns:

affine_transform – A dask array representing the transformed output

Return type:

Dask Array