code: def _extract_regions(img):
      R = {}
  
      # get hsv image
      hsv = skimage.color.rgb2hsv(img[:, :, :3])
  
      # pass 1: count pixel positions
      for y, i in enumerate(img):
          for x, (r, g, b, l) in enumerate(i):
              # initialize a new region
              if l not in R:
                  R[l] = {
                      "min_x": 0xFFFF,
                      "min_y": 0xFFFF,
                      "max_x": 0,
                      "max_y": 0,
                      "labels": [l],
                  }
  
              # bounding box
              if R[l]["min_x"] > x:
                  R[l]["min_x"] = x
              if R[l]["min_y"] > y:
                  R[l]["min_y"] = y
              if R[l]["max_x"] < x:
                  R[l]["max_x"] = x
              if R[l]["max_y"] < y:
                  R[l]["max_y"] = y
  
      # pass 2: calculate texture gradient
      tex_grad = _calc_texture_gradient(img)
  
      # pass 3: calculate colour histogram of each region
      for k, v in R.items():
          # colour histogram
          masked_pixels = hsv[:, :, :][img[:, :, 3] == k]
          R[k]["size"] = len(masked_pixels / 4)
          R[k]["hist_c"] = _calc_colour_hist(masked_pixels)
  
          # texture histogram
          R[k]["hist_t"] = _calc_texture_hist(
              tex_grad[:, :][img[:, :, 3] == k]
          )
  
      return R
  
imports: import sys
  from past.builtins import cmp
  import skimage.io
  import skimage.feature
  import skimage.color
  import skimage.transform
  import skimage.util
  import skimage.segmentation
  import numpy
label_desc: Use image node_id 10 for calling a global function with example usage: _extract_regions(img) and returns: R