code: def sort_by_direction_with_image_id_deprecated(pos_list, f_direction):
      """
      f_direction: h x w x 2
      pos_list: [[id, y, x], [id, y, x], [id, y, x] ...]
      """
      pos_list_full = np.array(pos_list).reshape(-1, 3)
      pos_list = pos_list_full[:, 1:]
      point_direction = f_direction[
          pos_list[:, 0], pos_list[:, 1]
      ]  # x, y
      point_direction = point_direction[:, ::-1]  # x, y -> y, x
      average_direction = np.mean(
          point_direction, axis=0, keepdims=True
      )
      pos_proj_leng = np.sum(pos_list * average_direction, axis=1)
      sorted_list = pos_list_full[np.argsort(pos_proj_leng)].tolist()
      return sorted_list
  
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 20 for calling a global function with example usage: sort_by_direction_with_image_id_deprecated(pos_list, f_direction) and returns: sorted_list