code: import numpy as np
  import cv2
  import matplotlib.pyplot as plt
  import matplotlib.image as mpimg
  import pickle
  
  
  # Read in an image
  image = mpimg.imread('../images/signs_vehicles_xygrad.png')
  
  def dir_threshold(img, sobel_kernel=3, thresh=(0, np.pi/2)):
  
      # Apply the following steps to img
      # 1) Convert to grayscale
      gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
      # 2) Take the gradient in x and y separately
      sobelx = cv2.Sobel(gray, cv2.CV_64F, 1,0,ksize=sobel_kernel )
      sobely = cv2.Sobel(gray, cv2.CV_64F, 0,1,ksize=sobel_kernel )
      # 3) Take the absolute value of the x and y gradients
      # 4) Use np.arctan2(abs_sobely, abs_sobelx) to calculate the direction of the gradient
      direction_gradient = np.arctan2(np.absolute(sobely), np.absolute(sobelx))
      # 5) Create a binary mask where direction thresholds are met
      binary_output = np.zeros_like(direction_gradient)
      binary_output[(direction_gradient >= thresh[0]) & (direction_gradient <= thresh[1])] = 1
      # 6) Return this mask as your binary_output image
      return binary_output
  
  
  # Run the function
  dir_binary = dir_threshold(image, sobel_kernel=15, thresh=(0.7, 1.3))
  # Plot the result
  f, (ax1, ax2) = plt.subplots(1, 2, figsize=(24, 9))
  f.tight_layout()
  ax1.imshow(image)
  ax1.set_title('Original Image', fontsize=50)
  ax2.imshow(dir_binary, cmap='gray')
  ax2.set_title('Thresholded Grad. Dir.', fontsize=50)
  plt.subplots_adjust(left=0., right=1, top=0.9, bottom=0.)
  plt.show()
apis: numpy.zeros_like matplotlib.pyplot.subplots matplotlib.pyplot.subplots_adjust matplotlib.pyplot.show numpy.absolute matplotlib.image.imread