code: def transform_segmentations(
      sample_collection,
      in_field,
      targets_map,
      output_dir=None,
      rel_dir=None,
      update=True,
      update_mask_targets=False,
      overwrite=False,
  ):
      """Transforms the segmentations in the given field according to the
      provided targets map.
  
      This method can be used to transform between grayscale and RGB masks, or it
      can be used to edit the pixel values or colors of masks without changing
      the number of channels.
  
      Note that any pixel values not in ``targets_map`` will be zero in the
      transformed masks.
  
      Args:
          sample_collection: a
              :class:`fiftyone.core.collections.SampleCollection`
          in_field: the name of the :class:`fiftyone.core.labels.Segmentation`
              field
          targets_map: a dict mapping existing pixel values (2D masks) or RGB hex
              strings (3D masks) to new pixel values or RGB hex strings to use.
              You may convert between grayscale and RGB using this argument
          output_dir (None): an optional directory in which to write the
              transformed images
          rel_dir (None): an optional relative directory to strip from each input
              filepath to generate a unique identifier that is joined with
              ``output_dir`` to generate an output path for each image. This
              argument allows for populating nested subdirectories in
              ``output_dir`` that match the shape of the input paths. The path is
              converted to an absolute path (if necessary) via
              :func:`fiftyone.core.storage.normalize_path`
          update (True): whether to update the mask paths on the instances
          update_mask_targets (False): whether to update the mask targets on the
              dataset to reflect the transformed targets
          overwrite (False): whether to delete ``output_dir`` prior to exporting
              if it exists
      """
      fov.validate_collection_label_fields(
          sample_collection, in_field, fol.Segmentation
      )
  
      samples = sample_collection.select_fields(in_field)
      in_field, processing_frames = samples._handle_frame_field(
          in_field
      )
  
      if output_dir is not None:
          if overwrite:
              etau.delete_dir(output_dir)
  
          filename_maker = fou.UniqueFilenameMaker(
              output_dir=output_dir, rel_dir=rel_dir, idempotent=False
          )
  
      for sample in samples.iter_samples(autosave=True, progress=True):
          if processing_frames:
              images = sample.frames.values()
          else:
              images = [sample]
  
          for image in images:
              label = image[in_field]
              if label is None:
                  continue
  
              if output_dir is not None:
                  outpath = filename_maker.get_output_path(
                      image.filepath, output_ext=".png"
                  )
              else:
                  outpath = None
  
              label.transform_mask(
                  targets_map, outpath=outpath, update=update
              )
  
      if update_mask_targets:
          mask_targets = sample_collection.mask_targets.get(
              in_field, None
          )
          if mask_targets is not None:
              sample_collection.mask_targets[
                  in_field
              ] = _transform_mask_targets(mask_targets, targets_map)
          else:
              mask_targets = sample_collection.default_mask_targets
              if mask_targets:
                  sample_collection.default_mask_targets = (
                      _transform_mask_targets(mask_targets, targets_map)
                  )
  
file_path: fiftyone/fiftyone/utils/labels.py
imports: import eta.core.utils
  import fiftyone.core.labels
  import fiftyone.core.utils
  import fiftyone.core.validation
label_desc: Use image node_id 4 for calling a global function with example usage: transform_segmentations(sample_collection, in_field, targets_map, output_dir, rel_dir, update, update_mask_targets, overwrite) without return types