code: def region_wise_metrics(
      regions, metric, prefix, keys=("pred", "label")
  ):
      all_metrics = dict()
      all_metrics[metric] = MeanDice(
          output_transform=from_engine(keys), include_background=False
      )
  
      if regions:
          labels = (
              regions
              if isinstance(regions, dict)
              else {
                  name: idx for idx, name in enumerate(regions, start=1)
              }
          )
          for name, idx in labels.items():
              all_metrics[f"{prefix}_{name}_mean_dice"] = MeanDice(
                  output_transform=from_engine_idx(keys, idx),
                  include_background=False,
              )
      return all_metrics
  
imports: from monai.config import KeysCollection
  from monai.handlers import MeanDice, RootMeanSquaredError, from_engine
  from monai.utils import ensure_tuple
label_desc: Use image node_id 1 for calling a global function with example usage: region_wise_metrics(regions, metric, prefix, keys) and returns: all_metrics