code: def compute_panoptic_quality(
      pred: torch.Tensor,
      gt: torch.Tensor,
      metric_name: str = "pq",
      remap: bool = True,
      match_iou_threshold: float = 0.5,
      smooth_numerator: float = 1e-6,
      output_confusion_matrix: bool = False,
  ) -> torch.Tensor:
      """Computes Panoptic Quality (PQ). If specifying `metric_name` to "SQ" or "RQ",
      Segmentation Quality (SQ) or Recognition Quality (RQ) will be returned instead.
  
      In addition, if `output_confusion_matrix` is True, the function will return a tensor with shape 4, which
      represents the true positive, false positive, false negative and the sum of iou. These four values are used to
      calculate PQ, and returning them directly enables further calculation over all images.
  
      Args:
          pred: input data to compute, it must be in the form of HW and have integer type.
          gt: ground truth. It must have the same shape as `pred` and have integer type.
          metric_name: output metric. The value can be "pq", "sq" or "rq".
          remap: whether to remap `pred` and `gt` to ensure contiguous ordering of instance id.
          match_iou_threshold: IOU threshold to determine the pairing between `pred` and `gt`. Usually,
              it should >= 0.5, the pairing between instances of `pred` and `gt` are identical.
              If set `match_iou_threshold` < 0.5, this function uses Munkres assignment to find the
              maximal amount of unique pairing.
          smooth_numerator: a small constant added to the numerator to avoid zero.
  
      Raises:
          ValueError: when `pred` and `gt` have different shapes.
          ValueError: when `match_iou_threshold` <= 0.0 or > 1.0.
  
      """
  
      if gt.shape != pred.shape:
          raise ValueError(
              f"pred and gt should have same shapes, got {pred.shape} and {gt.shape}."
          )
      if match_iou_threshold <= 0.0 or match_iou_threshold > 1.0:
          raise ValueError(
              f"'match_iou_threshold' should be within (0, 1], got: {match_iou_threshold}."
          )
  
      gt = gt.int()
      pred = pred.int()
  
      if remap is True:
          gt = remap_instance_id(gt)
          pred = remap_instance_id(pred)
  
      pairwise_iou, true_id_list, pred_id_list = _get_pairwise_iou(
          pred, gt, device=pred.device
      )
      paired_iou, paired_true, paired_pred = _get_paired_iou(
          pairwise_iou, match_iou_threshold, device=pairwise_iou.device
      )
  
      unpaired_true = [
          idx for idx in true_id_list[1:] if idx not in paired_true
      ]
      unpaired_pred = [
          idx for idx in pred_id_list[1:] if idx not in paired_pred
      ]
  
      tp, fp, fn = (
          len(paired_true),
          len(unpaired_pred),
          len(unpaired_true),
      )
      iou_sum = paired_iou.sum()
  
      if output_confusion_matrix:
          return torch.as_tensor(
              [tp, fp, fn, iou_sum], device=pred.device
          )
  
      metric_name = _check_panoptic_metric_name(metric_name)
      if metric_name == "rq":
          return torch.as_tensor(
              tp / (tp + 0.5 * fp + 0.5 * fn + smooth_numerator),
              device=pred.device,
          )
      if metric_name == "sq":
          return torch.as_tensor(
              iou_sum / (tp + smooth_numerator), device=pred.device
          )
      return torch.as_tensor(
          iou_sum / (tp + 0.5 * fp + 0.5 * fn + smooth_numerator),
          device=pred.device,
      )
  
file_path: MONAI/monai/metrics/panoptic_quality.py
imports: from __future__ import annotations
  from collections.abc import Sequence
  import torch
  from monai.metrics.metric import CumulativeIterationMetric
  from monai.metrics.utils import do_metric_reduction, remap_instance_id
  from monai.utils import MetricReduction, ensure_tuple, optional_import
label_desc: Use image node_id 1 for calling a global function with example usage: compute_panoptic_quality(pred, gt, metric_name, remap, match_iou_threshold, smooth_numerator, output_confusion_matrix) and returns: torch, torch, torch, torch