code: def binary_to_rle(binary_mask: np.ndarray) -> np.ndarray:
      """Converts a binary segmentation mask to RLE."""
      # Flatten mask and add -1 at beginning and end of array
      flat = np.concatenate(([-1], np.ravel(binary_mask), [-1]))
      # Find indices where a change to 0 or 1 happens
      borders = np.nonzero(np.diff(flat))[0]
      # Find counts of subsequent 0s and 1s
      rle = np.diff(borders)
      if flat[1]:
          # The first value in the encoding must always be the count
          # of initial 0s. If the mask starts with a 1 we must set
          # this count to 0.
          rle = np.concatenate(([0], rle))
      return rle
  
imports: import json
  import os
  import numpy
label_desc: Use image node_id 3 for calling a global function with example usage: binary_to_rle(binary_mask) and returns: rle