cupyx.scipy.ndimage.affine_transform#

cupyx.scipy.ndimage.affine_transform(input, matrix, offset=0.0, output_shape=None, output=None, order=3, mode='constant', cval=0.0, prefilter=True, *, texture_memory=False)[source]#

Apply an affine transformation.

Given an output image pixel index vector o, the pixel value is determined from the input image at position cupy.dot(matrix, o) + offset.

Parameters:
  • input (cupy.ndarray) – The input array.

  • matrix (cupy.ndarray) –

    The inverse coordinate transformation matrix, mapping output coordinates to input coordinates. If ndim is the number of dimensions of input, the given matrix must have one of the following shapes:

    • (ndim, ndim): the linear transformation matrix for each output coordinate.

    • (ndim,): assume that the 2D transformation matrix is diagonal, with the diagonal specified by the given value.

    • (ndim + 1, ndim + 1): assume that the transformation is specified using homogeneous coordinates. In this case, any value passed to offset is ignored.

    • (ndim, ndim + 1): as above, but the bottom row of a homogeneous transformation matrix is always [0, 0, ..., 1], and may be omitted.

  • offset (float or sequence) – 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) – Shape tuple.

  • output (cupy.ndarray or dtype) – The array in which to place the output, or the dtype of the returned array.

  • order (int) – The order of the spline interpolation, default is 3. Must be in the range 0-5.

  • mode (str) – Points outside the boundaries of the input are filled according to the given mode ('constant', 'nearest', 'mirror', 'reflect', 'wrap', 'grid-mirror', 'grid-wrap', 'grid-constant' or 'opencv').

  • cval (scalar) – Value used for points outside the boundaries of the input if mode='constant' or mode='opencv'. Default is 0.0

  • prefilter (bool) – Determines if the input array is prefiltered with spline_filter before interpolation. The default is True, which will create a temporary float64 array of filtered values if order > 1. If setting this to False, the output will be slightly blurred if order > 1, unless the input is prefiltered, i.e. it is the result of calling spline_filter on the original input.

  • texture_memory (bool) –

    If True, uses GPU texture memory. Supports only:

    • 2D and 3D float32 arrays as input

    • (ndim + 1, ndim + 1) homogeneous float32 transformation

      matrix

    • mode='constant' and mode='nearest'

    • order=0 (nearest neighbor) and order=1 (linear

      interpolation)

    • NVIDIA CUDA GPUs

Returns:

The transformed input. If output is given as a parameter, None is returned.

Return type:

cupy.ndarray or None