DOC: add visual example of edge modes

This commit is contained in:
Gregory R. Lee
2015-08-13 23:39:53 -04:00
parent a36ab880fc
commit c5a735420f
3 changed files with 65 additions and 2 deletions
+36
View File
@@ -0,0 +1,36 @@
"""
=========================
Interpolation: Edge Modes
=========================
This example illustrates the different edge modes available during
interpolation in routines such as ``skimage.transform.rescale`` and
``skimage.transform.resize``.
"""
from skimage._shared._interpolation_test import extend_image
import skimage.data
import matplotlib.pyplot as plt
import numpy as np
img = np.zeros((9, 9))
img[:8, :8] += 1
img[:4, :4] += 1
img[:2, :2] += 1
img[:1, :1] += 2
modes = ['constant', 'nearest', 'wrap', 'reflect']
fig, axes = plt.subplots(1, 4, figsize=(15, 5))
for n, mode in enumerate(modes):
img_extended = extend_image(img, pad=img.shape[0], mode=mode)
axes[n].imshow(img_extended, cmap=plt.cm.gray, interpolation='nearest')
axes[n].plot([8.5, 8.5], [8.5, 17.5], 'y--', linewidth=0.5)
axes[n].plot([17.5, 17.5], [8.5, 17.5], 'y--', linewidth=0.5)
axes[n].plot([8.5, 17.5], [8.5, 8.5], 'y--', linewidth=0.5)
axes[n].plot([8.5, 17.5], [17.5, 17.5], 'y--', linewidth=0.5)
axes[n].set_axis_off()
axes[n].set_aspect('equal')
axes[n].set_title(mode)
plt.tight_layout()
plt.show()