code: def _decode_segmentation(
      segmentation: Union[List[NestedDict], NestedDict],
      video: NestedDict,
      desired_height: int,
      desired_width: int,
  ):
      """Converts the run length encoded segmentation into an image."""
      pycocotools = tfds.core.lazy_imports.pycocotools
      rle = pycocotools.frPyObjects(
          segmentation, video["height"], video["width"]
      )
      if isinstance(segmentation, list):  # Polygon
          rle = pycocotools.merge(rle)
      segmentation = pycocotools.decode(rle)
      assert segmentation.shape[0] == video["height"]
      assert segmentation.shape[1] == video["width"]
      if (
          video["height"] != desired_height
          or video["width"] != desired_width
      ):
          cv2 = tfds.core.lazy_imports.cv2
          segmentation = cv2.resize(
              segmentation,
              (desired_width, desired_height),
              interpolation=cv2.INTER_NEAREST,
          )
      segmentation = np.expand_dims(segmentation, axis=-1)
      assert len(segmentation.shape) == 3
      return segmentation
  
imports: from __future__ import annotations
  import collections
  import json
  import os
  from typing import Any, Dict, List, Optional, Tuple, Union
  from etils import epath
  import numpy
  import tensorflow_datasets.public_api
label_desc: Use image node_id 2 for calling a global function with example usage: _decode_segmentation(segmentation, video, desired_height, desired_width) and returns: segmentation