多维图像处理 (cupyx.scipy.ndimage)#

过滤器#

convolve(input, weights[, output, mode, ...])

多维卷积。

convolve1d(input, weights[, axis, output, ...])

一维卷积。

correlate(input, weights[, output, mode, ...])

多维关联。

correlate1d(input, weights[, axis, output, ...])

一维相关。

gaussian_filter(input, sigma[, order, ...])

多维高斯滤波器。

gaussian_filter1d(input, sigma[, axis, ...])

沿给定轴的一维高斯滤波器。

gaussian_gradient_magnitude(input, sigma[, ...])

使用高斯导数的多维梯度幅度。

gaussian_laplace(input, sigma[, output, ...])

使用高斯二阶导数的二维拉普拉斯滤波器。

generic_filter(input, function[, size, ...])

使用提供的原始内核或缩减内核计算多维滤波器。

generic_filter1d(input, function, filter_size)

使用提供的原始内核沿给定轴计算一维滤波器。

generic_gradient_magnitude(input, derivative)

使用提供的导数函数的多维梯度幅度滤波器。

generic_laplace(input, derivative2[, ...])

使用提供的二阶导数函数的多维拉普拉斯滤波器。

laplace(input[, output, mode, cval])

基于近似二阶导数的多维拉普拉斯滤波器。

maximum_filter(input[, size, footprint, ...])

多维最大值滤波器。

maximum_filter1d(input, size[, axis, ...])

沿单个轴计算最大滤波器。

median_filter(input[, size, footprint, ...])

多维中值滤波器。

minimum_filter(input[, size, footprint, ...])

多维最小滤波器。

minimum_filter1d(input, size[, axis, ...])

沿单个轴计算最小滤波器。

percentile_filter(input, percentile[, size, ...])

多维百分位滤波器。

prewitt(input[, axis, output, mode, cval])

沿给定轴计算Prewitt滤波器。

rank_filter(input, rank[, size, footprint, ...])

多维排序滤波器。

sobel(input[, axis, output, mode, cval])

沿给定轴计算Sobel滤波器。

uniform_filter(input[, size, output, mode, ...])

多维均匀滤波器。

uniform_filter1d(input, size[, axis, ...])

沿给定轴的一维均匀滤波器。

傅里叶滤波器#

fourier_ellipsoid(input, size[, n, axis, output])

多维椭球傅里叶滤波器。

fourier_gaussian(input, sigma[, n, axis, output])

多维高斯偏移滤波器。

fourier_shift(input, shift[, n, axis, output])

多维傅里叶移位滤波器。

fourier_uniform(input, size[, n, axis, output])

多维均匀移位滤波器。

插值#

affine_transform(input, matrix[, offset, ...])

应用仿射变换。

map_coordinates(input, coordinates[, ...])

通过插值将输入数组映射到新坐标。

rotate(input, angle[, axes, reshape, ...])

旋转数组。

shift(input, shift[, output, order, mode, ...])

移动数组。

spline_filter(input[, order, output, mode])

多维样条滤波器。

spline_filter1d(input[, order, axis, ...])

沿着给定的轴计算一维样条滤波器。

zoom(input, zoom[, output, order, mode, ...])

缩放数组。

测量#

center_of_mass(input[, labels, index])

计算数组在标签处的值的质心。

extrema(input[, labels, index])

计算数组在标签处的值的最小值和最大值,以及它们的位置。

histogram(input, min, max, bins[, labels, index])

计算数组值的直方图,可选地在标签处。

label(input[, structure, output])

在数组中标记特征。

labeled_comprehension(input, labels, index, ...)

func 应用于每个标记区域后得到的数组。

maximum(input[, labels, index])

计算数组在标记区域上的值的最大值。

maximum_position(input[, labels, index])

查找数组在标签处的最大值的位置。

mean(input[, labels, index])

计算n-D图像数组值的平均值,可选地

median(input[, labels, index])

计算数组值在标记区域上的中位数。

minimum(input[, labels, index])

计算数组在标记区域上的值的最小值。

minimum_position(input[, labels, index])

在标签处找到数组值的最小值的位置。

standard_deviation(input[, labels, index])

计算n-D图像数组值的标准差,可以选择在指定的子区域进行。

sum_labels(input[, labels, index])

计算一个 n-D 图像数组值的总和,可选地

value_indices(arr, *[, ignore_value, ...])

在给定数组中查找每个不同值的索引。

variance(input[, labels, index])

计算n-D图像数组值的方差,可以选择在指定的子区域进行。

形态学#

binary_closing(input[, structure, ...])

使用给定的结构元素进行多维二进制闭合。

binary_dilation(input[, structure, ...])

使用给定的结构元素进行多维二值膨胀。

binary_erosion(input[, structure, ...])

使用给定的结构元素进行多维二值腐蚀。

binary_fill_holes(input[, structure, ...])

填充二进制对象中的空洞。

binary_hit_or_miss(input[, structure1, ...])

多维二进制命中或未命中变换。

binary_opening(input[, structure, ...])

使用给定的结构元素进行多维二进制开运算。

binary_propagation(input[, structure, mask, ...])

使用给定的结构元素进行多维二进制传播。

black_tophat(input[, size, footprint, ...])

多维黑帽滤波器。

distance_transform_edt(image[, sampling, ...])

精确的欧几里得距离变换。

generate_binary_structure(rank, connectivity)

生成二进制形态操作的二进制结构。

grey_closing(input[, size, footprint, ...])

计算多维灰度闭合。

grey_dilation(input[, size, footprint, ...])

计算灰度膨胀。

grey_erosion(input[, size, footprint, ...])

计算灰度腐蚀。

grey_opening(input[, size, footprint, ...])

计算多维灰度开运算。

iterate_structure(structure, iterations[, ...])

通过用自身膨胀来迭代一个结构。

morphological_gradient(input[, size, ...])

多维形态梯度。

morphological_laplace(input[, size, ...])

多维形态学拉普拉斯。

white_tophat(input[, size, footprint, ...])

多维白色顶帽滤波器。

OpenCV 模式#

cupyx.scipy.ndimage 支持额外的模式,opencv。如果指定此模式,函数将表现得像 cv2.warpAffinecv2.resize。示例:

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