code: def extract_main_direction(pos_list, f_direction):
      """
      f_direction: h x w x 2
      pos_list: [[y, x], [y, x], [y, x] ...]
      """
      pos_list = np.array(pos_list)
      point_direction = f_direction[pos_list[:, 0], pos_list[:, 1]]
      point_direction = point_direction[:, ::-1]  # x, y -> y, x
      average_direction = np.mean(
          point_direction, axis=0, keepdims=True
      )
      average_direction = average_direction / (
          np.linalg.norm(average_direction) + 1e-6
      )
      return average_direction
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import cv2
  import math
  import numpy
  from itertools import groupby
  from skimage.morphology._skeletonize import thin
label_desc: Use image node_id 19 for calling a global function with example usage: extract_main_direction(pos_list, f_direction) and returns: average_direction