You need to complete the following steps:
- Import the necessary modules:
import mathimport cv2import numpy as np
- Load the test images:
img = cv2.imread('../data/Lena.png')
- Prepare the per-pixel transformation maps:
xmap = np.zeros((img.shape[1], img.shape[0]), np.float32)ymap = np.zeros((img.shape[1], img.shape[0]), np.float32)for y in range(img.shape[0]): for x in range(img.shape[1]): xmap[y,x] = x + 30 * math.cos(20 * x / img.shape[0]) ymap[y,x] = y + 30 * math.sin(20 * y / img.shape[1])
- Remap the source image:
remapped_img = cv2.remap(img, xmap, ymap, cv2.INTER_LINEAR, None, cv2.BORDER_REPLICATE)
- Visualize the results:
plt.figure(0)plt.axis('off')plt.imshow(remapped_img[:,:,[2,1,0]])plt.show()