Chapter 5

  1. The cv2.split() function splits the source multi-channel image into several single-channel images,
    (b, g, r) = cv2.split(image).
  2. The cv2.merge() function merges several single-channel images into a multi-channel image, image = cv2.merge((b, g, r)).
  3. The image can be translated as follows:
height, width = image.shape[:2]
M = np.float32([[1, 0, 150], [0, 1, 300]])
dst_image = cv2.warpAffine(image, M, (width, height))

  1. The image can be rotated in the following manner:
height, width = image.shape[:2]
M = cv2.getRotationMatrix2D((width / 2.0, height / 2.0), 30, 1)
dst_image = cv2.warpAffine(image, M, (width, height))
  1. The image can be built as follows:
kernel = np.ones((5, 5), np.float32) / 25
smooth_image = cv2.filter2D(image, -1, kernel)
  1. The grayscale image is as follows:
M = np.ones(image.shape, dtype="uint8") * 40
added_image = cv2.add(image, M)
  1. COLORMAP_JET can be applied as follows: img_COLORMAP_JET = cv2.applyColorMap(gray_img, cv2.COLORMAP_JET)