code: def create_table_neighbour_code_to_contour_length(
      spacing_mm, device=None
  ):
      """
      Returns an array mapping neighbourhood code to the contour length.
      Adapted from https://github.com/deepmind/surface-distance
  
      In 2D, each point has 4 neighbors. Thus, are 16 configurations. A
      configuration is encoded with '1' meaning "inside the object" and '0' "outside
      the object". For example,
      "0101" and "1010" both encode an edge along the first spatial axis with length spacing[0] mm;
      "0011" and "1100" both encode an edge along the second spatial axis with length spacing[1] mm.
  
      Args:
          spacing_mm: 2-element list-like structure. Pixel spacing along the 1st and 2nd spatial axes.
          device: device to put the table on.
  
      Returns:
          A 16-element array mapping neighbourhood code to the contour length.
          ENCODING_KERNEL[2] which is the kernel used to compute the neighbourhood code.
      """
      spacing_mm = ensure_tuple_rep(spacing_mm, 2)
      (
          first,
          second,
      ) = spacing_mm  # spacing along the first and second spatial dimension respectively
      diag = 0.5 * np.linalg.norm(spacing_mm)
  
      neighbour_code_to_contour_length = np.zeros(
          [16], dtype=diag.dtype
      )
      neighbour_code_to_contour_length[int("0001", 2)] = diag
      neighbour_code_to_contour_length[int("0010", 2)] = diag
      neighbour_code_to_contour_length[int("0011", 2)] = second
      neighbour_code_to_contour_length[int("0100", 2)] = diag
      neighbour_code_to_contour_length[int("0101", 2)] = first
      neighbour_code_to_contour_length[int("0110", 2)] = 2 * diag
      neighbour_code_to_contour_length[int("0111", 2)] = diag
      neighbour_code_to_contour_length[int("1000", 2)] = diag
      neighbour_code_to_contour_length[int("1001", 2)] = 2 * diag
      neighbour_code_to_contour_length[int("1010", 2)] = first
      neighbour_code_to_contour_length[int("1011", 2)] = diag
      neighbour_code_to_contour_length[int("1100", 2)] = second
      neighbour_code_to_contour_length[int("1101", 2)] = diag
      neighbour_code_to_contour_length[int("1110", 2)] = diag
      neighbour_code_to_contour_length = convert_to_tensor(
          neighbour_code_to_contour_length, device=device
      )
      return neighbour_code_to_contour_length, torch.as_tensor(
          [[ENCODING_KERNEL[2]]], device=device
      )
  
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 11 for calling a global function with example usage: create_table_neighbour_code_to_contour_length(spacing_mm, device) and returns: neighbour_code_to_contour_length,  torch