code: def calc_surface_area(
      input_data, pixdim=None, affine=None, mask_value=0, mode="edges"
  ):
      """Reminder: Verify on real-world data.
      Also, some of the binarization feels clumsy/ineffecient.
      Also, this will over-estimate surface area, because
      it is counting cubes instead of, say, triangular
      surfaces
      """
  
      input_data, input_affine = read_image_files(
          input_data, return_affine=True
      )
  
      input_data = input_data[..., -1]
  
      pixdim = _get_pixdim(pixdim, affine, input_affine)
  
      if mode == "mesh":
          verts, faces = marching_cubes(input_data, 0, pixdim)
          surface_area = mesh_surface_area(verts, faces)
  
      elif mode == "edges":
          edges_kernel = np.zeros((3, 3, 3), dtype=float)
          edges_kernel[1, 1, 0] = -1 * pixdim[0] * pixdim[1]
          edges_kernel[0, 1, 1] = -1 * pixdim[1] * pixdim[2]
          edges_kernel[1, 0, 1] = -1 * pixdim[0] * pixdim[2]
          edges_kernel[1, 2, 1] = -1 * pixdim[0] * pixdim[2]
          edges_kernel[2, 1, 1] = -1 * pixdim[1] * pixdim[2]
          edges_kernel[1, 1, 2] = -1 * pixdim[0] * pixdim[1]
          edges_kernel[1, 1, 1] = 1 * (
              2 * pixdim[0] * pixdim[1]
              + 2 * pixdim[0] * pixdim[2]
              + 2 * pixdim[1] * pixdim[2]
          )
  
          label_numpy = np.copy(input_data)
          label_numpy[label_numpy != mask_value] = 1
          label_numpy[label_numpy == mask_value] = 0
  
          edge_image = signal.convolve(
              label_numpy, edges_kernel, mode="same"
          )
          edge_image[edge_image < 0] = 0
  
          surface_area = np.sum(edge_image)
  
      else:
          print(
              (
                  "Warning, mode parameter",
                  mode,
                  "not available. Returning None.",
              )
          )
          surface_area = None
  
      return surface_area
  
file_path: DeepNeuro/deepneuro/outputs/measure.py
imports: import numpy
  from skimage.morphology import label
  from skimage.measure import regionprops, mesh_surface_area, marching_cubes
  from scipy import signal
  from deepneuro.utilities.conversion import read_image_files
label_desc: Use image node_id 4 for calling a global function with example usage: calc_surface_area(input_data, pixdim, affine, mask_value, mode) and returns: surface_area