code: def segment_image(image, segment_mask):
      image_array = np.array(image)
      gray_image = Image.new("RGB", image.size, (128, 128, 128))
      segmented_image_array = np.zeros_like(image_array)
      segmented_image_array[segment_mask] = image_array[segment_mask]
      segmented_image = Image.fromarray(segmented_image_array)
      transparency = np.zeros_like(segment_mask, dtype=np.uint8)
      transparency[segment_mask] = 255
      transparency_image = Image.fromarray(transparency, mode="L")
      gray_image.paste(segmented_image, mask=transparency_image)
      return gray_image
  
imports: import os
  import cv2
  import time
  import sys
  import argparse
  import paddle
  import paddle.nn.functional
  import numpy
  from PIL import Image, ImageDraw
  import matplotlib.pyplot
  from segment_anything import sam_model_registry, SamAutomaticMaskGenerator
  from segment_anything.modeling.clip_paddle import build_clip_model, _transform
  from segment_anything.utils.sample_tokenizer import tokenize
  from paddleseg.utils.visualize import get_pseudo_color_map, get_color_map_list
label_desc: Use image node_id 2 for calling a global function with example usage: segment_image(image, segment_mask) and returns: gray_image