code: def get_surface_distance(
      seg_pred: NdarrayOrTensor,
      seg_gt: NdarrayOrTensor,
      distance_metric: str = "euclidean",
      spacing: int
      | float
      | np.ndarray
      | Sequence[int | float]
      | None = None,
  ) -> NdarrayOrTensor:
      """
      This function is used to compute the surface distances from `seg_pred` to `seg_gt`.
  
      Args:
          seg_pred: the edge of the predictions.
          seg_gt: the edge of the ground truth.
          distance_metric: : [``"euclidean"``, ``"chessboard"``, ``"taxicab"``]
              the metric used to compute surface distance. Defaults to ``"euclidean"``.
  
              - ``"euclidean"``, uses Exact Euclidean distance transform.
              - ``"chessboard"``, uses `chessboard` metric in chamfer type of transform.
              - ``"taxicab"``, uses `taxicab` metric in chamfer type of transform.
          spacing: spacing of pixel (or voxel). This parameter is relevant only if ``distance_metric`` is set to ``"euclidean"``.
              Several input options are allowed:
              (1) If a single number, isotropic spacing with that value is used.
              (2) If a sequence of numbers, the length of the sequence must be equal to the image dimensions.
              (3) If ``None``, spacing of unity is used. Defaults to ``None``.
  
      Note:
          If seg_pred or seg_gt is all 0, may result in nan/inf distance.
  
      """
      lib: ModuleType = (
          torch if isinstance(seg_pred, torch.Tensor) else np
      )
      if not seg_gt.any():
          dis = np.inf * lib.ones_like(seg_gt, dtype=lib.float32)
      else:
          if not lib.any(seg_pred):
              dis = np.inf * lib.ones_like(seg_gt, dtype=lib.float32)
              dis = dis[seg_gt]
              return convert_to_dst_type(
                  dis, seg_pred, dtype=dis.dtype
              )[0]
          if distance_metric == "euclidean":
              dis = monai_distance_transform_edt((~seg_gt)[None, ...], sampling=spacing)[0]  # type: ignore
          elif distance_metric in {"chessboard", "taxicab"}:
              dis = distance_transform_cdt(
                  convert_to_numpy(~seg_gt), metric=distance_metric
              )
          else:
              raise ValueError(
                  f"distance_metric {distance_metric} is not implemented."
              )
      dis = convert_to_dst_type(dis, seg_pred, dtype=lib.float32)[0]
      return dis[seg_pred]
  
imports: from __future__ import annotations
  import warnings
  from functools import lru_cache, partial
  from types import ModuleType
  from typing import Any, Iterable, Sequence
  import numpy
  import torch
  from monai.config import NdarrayOrTensor, NdarrayTensor
  from monai.transforms.croppad.dictionary import CropForegroundD
  from monai.transforms.utils import distance_transform_edt
  from monai.utils import MetricReduction, convert_to_cupy, convert_to_dst_type, convert_to_numpy, convert_to_tensor, deprecated_arg, deprecated_arg_default, ensure_tuple_rep, look_up_option, optional_import
label_desc: Use image node_id 4 for calling a global function with example usage: get_surface_distance(seg_pred, seg_gt, distance_metric, spacing) and returns: dis, convert_to_dst_type