注意
前往結尾以下載完整的範例程式碼。或透過 Binder 在您的瀏覽器中執行此範例
內插:邊緣模式#
此範例說明在例行程序(例如 skimage.transform.rescale()
和 skimage.transform.resize()
)中內插期間可用的不同邊緣模式。

import numpy as np
import matplotlib.pyplot as plt
img = np.zeros((16, 16))
img[:8, :8] += 1
img[:4, :4] += 1
img[:2, :2] += 1
img[:1, :1] += 2
img[8, 8] = 4
modes = ['constant', 'edge', 'wrap', 'reflect', 'symmetric']
fig, axes = plt.subplots(2, 3)
ax = axes.flatten()
for n, mode in enumerate(modes):
img_padded = np.pad(img, pad_width=img.shape[0], mode=mode)
ax[n].imshow(img_padded, cmap=plt.cm.gray)
ax[n].plot(
[15.5, 15.5, 31.5, 31.5, 15.5],
[15.5, 31.5, 31.5, 15.5, 15.5],
'y--',
linewidth=0.5,
)
ax[n].set_title(mode)
for a in ax:
a.set_axis_off()
a.set_aspect('equal')
plt.tight_layout()
plt.show()
指令碼的總執行時間: (0 分鐘 0.343 秒)