In [1]:
import cv2
import numpy as np
import matplotlib.pyplot as plt
import scipy.ndimage as scp
In [2]:
bike = cv2.imread('bike.jpg', cv2.IMREAD_GRAYSCALE)
img = bike[250:550,400:650]
In [3]:
Right_shift = np.zeros((150,150))
Right_shift[74,0] = 1 # 1 on left column and the middle row of array and rest all zero
filtered_Right_shift = scp.correlate(img, Right_shift)
In [4]:
plt.figure(figsize=(10,8))
plt.subplot(1,2,1), plt.imshow(img, cmap='gray'), plt.title('Original')
Out[4]:
In [5]:
plt.subplot(1,2,2), plt.imshow(filtered_Right_shift, cmap='gray'), plt.title('Right Shifted')
Out[5]:
In [6]:
plt.show()
In [7]:
Left_shift = np.zeros((150,150))
Left_shift[74,149] = 1 # 1 on bottom row and the middle column of array and rest all zero
filtered_Left_shift = scp.correlate(img, Left_shift)
plt.figure(figsize=(10,8))
plt.subplot(1,2,1), plt.imshow(img, cmap='gray'), plt.title('Original')
plt.subplot(1,2,2), plt.imshow(filtered_Left_shift, cmap='gray'), plt.title('Left Shifted')
plt.show()
In [8]:
Top_shift = np.zeros((150,150))
Top_shift[149,74] = 1 # 1 on bottom row and the middle column of array and rest all zero
filtered_Top_shift = scp.correlate(img, Top_shift)
plt.figure(figsize=(10,8))
plt.subplot(1,2,1), plt.imshow(img, cmap='gray'), plt.title('Original')
plt.subplot(1,2,2), plt.imshow(filtered_Top_shift, cmap='gray'), plt.title('Top Shifted')
plt.show()
In [9]:
Bottom_shift = np.zeros((150,150))
Bottom_shift[0,74] = 1 # 1 on bottom row and the middle column of array and rest all zero
filtered_Bottom_shift = scp.correlate(img, Bottom_shift)
plt.figure(figsize=(10,8))
plt.subplot(1,2,1), plt.imshow(img, cmap='gray'), plt.title('Original')
plt.subplot(1,2,2), plt.imshow(filtered_Bottom_shift, cmap='gray'), plt.title('Bottom Shifted')
plt.show()