1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| from scipy import signal from scipy import misc import matplotlib.pyplot as plt import numpy as np import scipy.ndimage as sn
im = misc.imread("data/zebra.png", flatten=True)
flt = np.array([[-1, 0, 1], [-2, 0, 2], [-1, 0, 1]])
flt2 = np.array([[1, 2, 1], [0, 0, 0], [-1, -2, -1]])
conv_img1 = signal.convolve2d(im, flt, boundary='symm', mode='same').astype("int32")
conv_img2 = signal.convolve2d(im, flt2, boundary='symm', mode='same').astype("int32")
plt.figure("Conv2D") plt.subplot(131) plt.imshow(im, cmap='gray') plt.xticks([]) plt.yticks([])
plt.subplot(132) plt.xticks([]) plt.yticks([]) plt.imshow(conv_img1, cmap='gray')
plt.subplot(133) plt.xticks([]) plt.yticks([]) plt.imshow(conv_img2, cmap='gray')
plt.show()
|