dask_image.ndinterp package
dask_image.ndinterp package¶
- dask_image.ndinterp.affine_transform(image, matrix, offset=0.0, output_shape=None, order=1, output_chunks=None, **kwargs)[source]¶
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.
Notes
Differences to ndimage.affine_transformation: - currently, prefiltering is not supported
(affecting the output in case of interpolation order > 1)
default order is 1
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, ndim), (ndim, ndim+1) or (ndim+1, ndim+1)) – Transformation matrix.
offset (float or sequence, optional) – The offset into the array where the transform is applied. If a float, offset is the same for each axis. If a sequence, offset should contain one value for each axis.
output_shape (tuple of ints, optional) – The shape of the array to be returned.
order (int, optional) – The order of the spline interpolation. Note that for order>1 scipy’s affine_transform applies prefiltering, which is not yet supported and skipped in this implementation.
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
- dask_image.ndinterp.rotate(input_arr, angle, axes=(1, 0), reshape=True, output_chunks=None, **kwargs)[source]¶
Rotate an array using Dask.
The array is rotated in the plane defined by the two axes given by the axes parameter using spline interpolation of the requested order.
Chunkwise processing is performed using dask_image.ndinterp.affine_transform, for which further parameters supported by the ndimage functions can be passed as keyword arguments.
Notes
Differences to ndimage.rotate: - currently, prefiltering is not supported
(affecting the output in case of interpolation order > 1)
default order is 1
modes ‘reflect’, ‘mirror’ and ‘wrap’ are not supported
Arguments are equal to ndimage.rotate except for - output (not present here) - output_chunks (relevant in the dask array context)
- Parameters
input_arr (array_like (Numpy Array, Cupy Array, Dask Array...)) – The image array.
angle (float) – The rotation angle in degrees.
axes (tuple of 2 ints, optional) – The two axes that define the plane of rotation. Default is the first two axes.
reshape (bool, optional) – If reshape is true, the output shape is adapted so that the input array is contained completely in the output. Default is True.
output_chunks (tuple of ints, optional) – The shape of the chunks of the output Dask Array.
**kwargs (dict, optional) – Additional keyword arguments are passed to dask_image.ndinterp.affine_transform.
- Returns
rotate – A dask array representing the rotated input.
- Return type
Dask Array
Examples
>>> from scipy import ndimage, misc >>> import matplotlib.pyplot as plt >>> import dask.array as da >>> fig = plt.figure(figsize=(10, 3)) >>> ax1, ax2, ax3 = fig.subplots(1, 3) >>> img = da.from_array(misc.ascent(),chunks=(64,64)) >>> img_45 = dask_image.ndinterp.rotate(img, 45, reshape=False) >>> full_img_45 = dask_image.ndinterp.rotate(img, 45, reshape=True) >>> ax1.imshow(img, cmap='gray') >>> ax1.set_axis_off() >>> ax2.imshow(img_45, cmap='gray') >>> ax2.set_axis_off() >>> ax3.imshow(full_img_45, cmap='gray') >>> ax3.set_axis_off() >>> fig.set_tight_layout(True) >>> plt.show() >>> print(img.shape) (512, 512) >>> print(img_45.shape) (512, 512) >>> print(full_img_45.shape) (724, 724)