Multi-dimensional image processing

CuPy provides multi-dimensional image processing functions. It supports a subset of scipy.ndimage interface.

Filters

cupyx.scipy.ndimage.convolve

Multi-dimensional convolution.

cupyx.scipy.ndimage.convolve1d

One-dimensional convolution.

cupyx.scipy.ndimage.correlate

Multi-dimensional correlate.

cupyx.scipy.ndimage.correlate1d

One-dimensional correlate.

cupyx.scipy.ndimage.gaussian_filter

Multi-dimensional Gaussian filter.

cupyx.scipy.ndimage.gaussian_filter1d

One-dimensional Gaussian filter along the given axis.

cupyx.scipy.ndimage.gaussian_gradient_magnitude

Multi-dimensional gradient magnitude using Gaussian derivatives.

cupyx.scipy.ndimage.gaussian_laplace

Multi-dimensional Laplace filter using Gaussian second derivatives.

cupyx.scipy.ndimage.generic_filter

Compute a multi-dimensional filter using the provided raw kernel or reduction kernel.

cupyx.scipy.ndimage.generic_filter1d

Compute a 1D filter along the given axis using the provided raw kernel.

cupyx.scipy.ndimage.generic_gradient_magnitude

Multi-dimensional gradient magnitude filter using a provided derivative function.

cupyx.scipy.ndimage.generic_laplace

Multi-dimensional Laplace filter using a provided second derivative function.

cupyx.scipy.ndimage.laplace

Multi-dimensional Laplace filter based on approximate second derivatives.

cupyx.scipy.ndimage.maximum_filter

Multi-dimensional maximum filter.

cupyx.scipy.ndimage.maximum_filter1d

Compute the maximum filter along a single axis.

cupyx.scipy.ndimage.median_filter

Multi-dimensional median filter.

cupyx.scipy.ndimage.minimum_filter

Multi-dimensional minimum filter.

cupyx.scipy.ndimage.minimum_filter1d

Compute the minimum filter along a single axis.

cupyx.scipy.ndimage.percentile_filter

Multi-dimensional percentile filter.

cupyx.scipy.ndimage.prewitt

Compute a Prewitt filter along the given axis.

cupyx.scipy.ndimage.rank_filter

Multi-dimensional rank filter.

cupyx.scipy.ndimage.sobel

Compute a Sobel filter along the given axis.

cupyx.scipy.ndimage.uniform_filter

Multi-dimensional uniform filter.

cupyx.scipy.ndimage.uniform_filter1d

One-dimensional uniform filter along the given axis.

Fourier Filters

cupyx.scipy.ndimage.fourier_gaussian

Multidimensional Gaussian shift filter.

cupyx.scipy.ndimage.fourier_shift

Multidimensional Fourier shift filter.

cupyx.scipy.ndimage.fourier_uniform

Multidimensional uniform shift filter.

Interpolation

cupyx.scipy.ndimage.affine_transform

Apply an affine transformation.

cupyx.scipy.ndimage.map_coordinates

Map the input array to new coordinates by interpolation.

cupyx.scipy.ndimage.rotate

Rotate an array.

cupyx.scipy.ndimage.shift

Shift an array.

cupyx.scipy.ndimage.zoom

Zoom an array.

Measurements

cupyx.scipy.ndimage.extrema

Calculate the minimums and maximums of the values of an array at labels, along with their positions.

cupyx.scipy.ndimage.label

Labels features in an array.

cupyx.scipy.ndimage.maximum

Calculate the maximum of the values of an array over labeled regions.

cupyx.scipy.ndimage.maximum_position

Find the positions of the maximums of the values of an array at labels.

cupyx.scipy.ndimage.mean

Calculates the mean of the values of an n-D image array, optionally

cupyx.scipy.ndimage.median

Calculate the median of the values of an array over labeled regions.

cupyx.scipy.ndimage.minimum

Calculate the minimum of the values of an array over labeled regions.

cupyx.scipy.ndimage.minimum_position

Find the positions of the minimums of the values of an array at labels.

cupyx.scipy.ndimage.standard_deviation

Calculates the standard deviation of the values of an n-D image array, optionally at specified sub-regions.

cupyx.scipy.ndimage.sum

Calculates the sum of the values of an n-D image array, optionally

cupyx.scipy.ndimage.variance

Calculates the variance of the values of an n-D image array, optionally at specified sub-regions.

Morphology

cupyx.scipy.ndimage.grey_closing

Calculates a multi-dimensional greyscale closing.

cupyx.scipy.ndimage.grey_dilation

Calculates a greyscale dilation.

cupyx.scipy.ndimage.grey_erosion

Calculates a greyscale erosion.

cupyx.scipy.ndimage.grey_opening

Calculates a multi-dimensional greyscale opening.

OpenCV mode

cupyx.scipy.ndimage supports additional mode, opencv. If it is given, the function performs like cv2.warpAffine or cv2.resize. Example:

import cupyx.scipy.ndimage
import cupy as cp
import cv2

im = cv2.imread('TODO') # pls fill in your image path

trans_mat = cp.eye(4)
trans_mat[0][0] = trans_mat[1][1] = 0.5

smaller_shape = (im.shape[0] // 2, im.shape[1] // 2, 3)
smaller = cp.zeros(smaller_shape) # preallocate memory for resized image

cupyx.scipy.ndimage.affine_transform(im, trans_mat, output_shape=smaller_shape,
                                     output=smaller, mode='opencv')

cv2.imwrite('smaller.jpg', cp.asnumpy(smaller)) # smaller image saved locally