构建形象金字塔

这个 pyramid_gaussian 函数获取图像并生成按恒定比例因数缩小的连续图像。图像金字塔通常用于例如实现去噪、纹理识别和尺度不变检测的算法。

plot pyramid

输出:

/scikit-image/doc/examples/transform/plot_pyramid.py:21: FutureWarning:

`multichannel` is a deprecated argument name for `pyramid_gaussian`. It will be removed in version 1.0. Please use `channel_axis` instead.

import numpy as np
import matplotlib.pyplot as plt

from skimage import data
from skimage.transform import pyramid_gaussian


image = data.astronaut()
rows, cols, dim = image.shape
pyramid = tuple(pyramid_gaussian(image, downscale=2, multichannel=True))

composite_image = np.zeros((rows, cols + cols // 2, 3), dtype=np.double)

composite_image[:rows, :cols, :] = pyramid[0]

i_row = 0
for p in pyramid[1:]:
    n_rows, n_cols = p.shape[:2]
    composite_image[i_row:i_row + n_rows, cols:cols + n_cols] = p
    i_row += n_rows

fig, ax = plt.subplots()
ax.imshow(composite_image)
plt.show()

脚本的总运行时间: (0分0.196秒)

Gallery generated by Sphinx-Gallery