code: def replace_cryptomatte_hashes_by_asset_index(
      segmentation_ids: ArrayLike, assets: Sequence[core.assets.Asset]
  ):
      """Replace (inplace) the cryptomatte hash (from Blender) by the index of each asset + 1.
      (the +1 is to ensure that the 0 for background does not interfere with asset index 0)
  
      Args:
        segmentation_ids: Segmentation array of cryptomatte hashes as returned by Blender.
        assets: List of assets to use for replacement.
      """
      # replace crypto-ids with asset index
      new_segmentation_ids = np.zeros_like(segmentation_ids)
      for idx, asset in enumerate(assets, start=1):
          asset_hash = mm3hash(asset.uid)
          new_segmentation_ids[segmentation_ids == asset_hash] = idx
      return new_segmentation_ids
  
imports: import contextlib
  import copy
  import functools
  import sys
  from typing import Dict, Sequence, Tuple, Union
  import numpy
  import OpenEXR
  import Imath
  import sklearn.utils
  import trimesh
  from kubric import core
  from kubric.kubric_typing import AddAssetFunction, ArrayLike
  from kubric.redirect_io import RedirectStream
  from kubric.safeimport.bpy import bpy
label_desc: Use image node_id 8 for calling a global function with example usage: replace_cryptomatte_hashes_by_asset_index(segmentation_ids, assets) and returns: new_segmentation_ids