本文简要介绍 python 语言中 scipy.ndimage.zoom
的用法。
用法:
scipy.ndimage.zoom(input, zoom, output=None, order=3, mode='constant', cval=0.0, prefilter=True, *, grid_mode=False)#
缩放数组。
使用请求顺序的样条插值对数组进行缩放。
- input: array_like
输入数组。
- zoom: 浮点数或序列
沿轴的缩放系数。如果是浮点数,
zoom
对于每个轴都是相同的。如果是序列,zoom
应为每个轴包含一个值。- output: 数组或数据类型,可选
放置输出的数组,或返回数组的 dtype。默认情况下,将创建一个与输入具有相同 dtype 的数组。
- order: 整数,可选
样条插值的阶数,默认为 3。阶数必须在 0-5 范围内。
- mode: {‘reflect’、‘grid-mirror’、‘constant’、‘grid-constant’、‘nearest’、‘mirror’、‘grid-wrap’、‘wrap’},可选
模式参数确定输入数组如何扩展到其边界之外。默认为‘constant’。每个有效值的行为如下(请参阅其他图表和详细信息边界模式):
- ‘reflect’ (d c b a | a b c d | d c b a)
通过反射最后一个像素的边来扩展输入。此模式有时也称为half-sample 对称模式。
- ‘grid-mirror’
这是‘reflect’ 的同义词。
- ‘constant’ (k k k k | a b c d |呸呸呸呸)
通过使用 cval 参数定义的相同常量值填充边之外的所有值来扩展输入。在输入边之外不执行插值。
- ‘grid-constant’ (k k k k | a b c d |呸呸呸呸)
通过使用 cval 参数定义的相同常量值填充边之外的所有值来扩展输入。插值也会发生在输入范围之外的样本上。
- ‘nearest’ (啊啊啊啊| a b c d |嘀嘀嘀嘀)
通过复制最后一个像素来扩展输入。
- ‘mirror’ (d c b | a b c d | c b a)
通过反射最后一个像素的中心来扩展输入。此模式有时也称为whole-sample 对称模式。
- ‘grid-wrap’ (a b c d | a b c d | A B C D)
通过环绕到相对边来扩展输入。
- ‘wrap’ (d b c d | a b c d | b c a b)
输入通过环绕到相反的边来扩展,但是以某种方式使最后一个点和初始点完全重叠。在这种情况下,没有很好地定义在重叠点将选择哪个样本。
- cval: 标量,可选
如果模式为‘constant’,则填充过去输入边的值。默认值为 0.0。
- prefilter: 布尔型,可选
确定输入数组是否经过预过滤scipy.ndimage.spline_filter插值之前。默认为 True,这将创建一个临时浮点数64过滤值数组 if订单 > 1.如果将此设置为 False,则输出会稍微模糊,如果订单 > 1, 除非输入是预过滤的,即它是调用的结果scipy.ndimage.spline_filter在原始输入上。
- grid_mode: 布尔型,可选
如果为 False,则放大像素中心的距离。否则,使用包括全像素范围的距离。例如,当 grid_mode 为 False 时,长度为 5 的一维信号被认为具有长度 4,但当 grid_mode 为 True 时,长度为 5。请参见以下视觉示例:
| pixel 1 | pixel 2 | pixel 3 | pixel 4 | pixel 5 | |<-------------------------------------->| vs. |<----------------------------------------------->|
上图中箭头的起点对应于每种模式下的坐标位置 0。
- zoom: ndarray
缩放的输入。
参数 ::
返回 ::
注意:
对于complex-valued 输入,此函数独立缩放实部和虚部。
例子:
>>> from scipy import ndimage, datasets >>> import matplotlib.pyplot as plt
>>> fig = plt.figure() >>> ax1 = fig.add_subplot(121) # left side >>> ax2 = fig.add_subplot(122) # right side >>> ascent = datasets.ascent() >>> result = ndimage.zoom(ascent, 3.0) >>> ax1.imshow(ascent, vmin=0, vmax=255) >>> ax2.imshow(result, vmin=0, vmax=255) >>> plt.show()
>>> print(ascent.shape) (512, 512)
>>> print(result.shape) (1536, 1536)
相关用法
- Python SciPy ndimage.correlate用法及代码示例
- Python SciPy ndimage.morphological_gradient用法及代码示例
- Python SciPy ndimage.variance用法及代码示例
- Python SciPy ndimage.correlate1d用法及代码示例
- Python SciPy ndimage.binary_dilation用法及代码示例
- Python SciPy ndimage.distance_transform_bf用法及代码示例
- Python SciPy ndimage.find_objects用法及代码示例
- Python SciPy ndimage.label用法及代码示例
- Python SciPy ndimage.maximum_filter1d用法及代码示例
- Python SciPy ndimage.iterate_structure用法及代码示例
- Python SciPy ndimage.map_coordinates()用法及代码示例
- Python SciPy ndimage.generic_laplace用法及代码示例
- Python SciPy ndimage.generate_binary_structure用法及代码示例
- Python SciPy ndimage.binary_opening用法及代码示例
- Python SciPy ndimage.binary_fill_holes用法及代码示例
- Python SciPy ndimage.maximum_filter用法及代码示例
- Python SciPy ndimage.minimum_position用法及代码示例
- Python SciPy ndimage.labeled_comprehension用法及代码示例
- Python SciPy ndimage.grey_erosion用法及代码示例
- Python SciPy ndimage.spline_filter用法及代码示例
- Python SciPy ndimage.shift用法及代码示例
- Python SciPy ndimage.distance_transform_cdt用法及代码示例
- Python SciPy ndimage.minimum用法及代码示例
- Python SciPy ndimage.fourier_uniform用法及代码示例
- Python SciPy ndimage.gaussian_laplace用法及代码示例
注:本文由纯净天空筛选整理自scipy.org大神的英文原创作品 scipy.ndimage.zoom。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。