1""" 2========================= 3Interpolation: Edge Modes 4========================= 5 6This example illustrates the different edge modes available during 7interpolation in routines such as :py:func:`skimage.transform.rescale` 8and :py:func:`skimage.transform.resize`. 9""" 10import numpy as np 11import matplotlib.pyplot as plt 12 13 14img = np.zeros((16, 16)) 15img[:8, :8] += 1 16img[:4, :4] += 1 17img[:2, :2] += 1 18img[:1, :1] += 2 19img[8, 8] = 4 20 21modes = ['constant', 'edge', 'wrap', 'reflect', 'symmetric'] 22fig, axes = plt.subplots(2, 3) 23ax = axes.flatten() 24 25for n, mode in enumerate(modes): 26 img_padded = np.pad(img, pad_width=img.shape[0], mode=mode) 27 ax[n].imshow(img_padded, cmap=plt.cm.gray) 28 ax[n].plot([15.5, 15.5, 31.5, 31.5, 15.5], 29 [15.5, 31.5, 31.5, 15.5, 15.5], 'y--', linewidth=0.5) 30 ax[n].set_title(mode) 31 32for a in ax: 33 a.set_axis_off() 34 a.set_aspect('equal') 35 36plt.tight_layout() 37plt.show() 38