code: def get_coco_segmentation_from_bool_mask(bool_mask):
      """
      Convert boolean mask to coco segmentation format
      [
          [x1, y1, x2, y2, x3, y3, ...],
          [x1, y1, x2, y2, x3, y3, ...],
          ...
      ]
      """
      # Generate polygons from mask
      mask = np.squeeze(bool_mask)
      mask = mask.astype(np.uint8)
      mask = cv2.copyMakeBorder(
          mask, 1, 1, 1, 1, cv2.BORDER_CONSTANT, value=0
      )
      polygons = cv2.findContours(
          mask, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE, offset=(-1, -1)
      )
      polygons = polygons[0] if len(polygons) == 2 else polygons[1]
      # Convert polygon to coco segmentation
      coco_segmentation = []
      for polygon in polygons:
          segmentation = polygon.flatten().tolist()
          # at least 3 points needed for a polygon
          if len(segmentation) >= 6:
              coco_segmentation.append(segmentation)
      return coco_segmentation
  
imports: import copy
  import os
  import random
  import time
  from typing import List, Optional, Union
  import cv2
  import numpy
  import requests
  from PIL import Image
  from sahi.utils.file import Path
label_desc: Use image node_id 11 for calling a global function with example usage: get_coco_segmentation_from_bool_mask(bool_mask) and returns: coco_segmentation