code: def shape_based_slice_interpolation(img, dim, nslices):
      """
      Adds `nslices` slices between all slices of the binary image `img` along dimension
      `dim` respecting the original slice values to be situated in the middle of each
      slice. Extrapolation situations are handled by simple repeating.
  
      Interpolation of new slices is performed using shape based interpolation.
  
      Parameters
      ----------
      img : array_like
          A n-dimensional image.
      dim : int
          The dimension along which to add slices.
      nslices : int
          The number of slices to add. Must be an even number.
  
      Returns
      -------
      out : ndarray
          The re-sampled image.
      """
      # check arguments
      if not 0 == nslices % 2:
          raise ValueError("nslices must be an even number")
  
      out = None
      slicer = [slice(None)] * img.ndim
      chunk_full_shape = list(img.shape)
      chunk_full_shape[dim] = nslices + 2
  
      for sl1, sl2 in zip(
          numpy.rollaxis(img, dim)[:-1], numpy.rollaxis(img, dim)[1:]
      ):
          if 0 == numpy.count_nonzero(sl1) and 0 == numpy.count_nonzero(
              sl2
          ):
              chunk = numpy.zeros(chunk_full_shape, dtype=numpy.bool_)
          else:
              chunk = shape_based_slice_insertation_object_wise(
                  sl1, sl2, dim, nslices
              )
          if out is None:
              out = numpy.delete(chunk, -1, dim)
          else:
              out = numpy.concatenate(
                  (out, numpy.delete(chunk, -1, dim)), dim
              )
  
      slicer[dim] = numpy.newaxis
      out = numpy.concatenate((out, sl2[slicer]), dim)
  
      slicer[dim] = slice(0, 1)
      for _ in range(nslices // 2):
          out = numpy.concatenate((img[slicer], out), dim)
      slicer[dim] = slice(-1, None)
      for _ in range(nslices // 2):
          out = numpy.concatenate((out, img[slicer]), dim)
  
      return out
  
file_path: medpy/bin/medpy_binary_resampling.py
imports: import os
  import logging
  import argparse
  import numpy
  from scipy.ndimage import zoom
  from scipy.ndimage import distance_transform_edt, binary_erosion
  from scipy.ndimage import label
  from medpy.core import Logger
  from medpy.filter import resample, bounding_box
  from medpy.utilities import argparseu
  from medpy.io import load, save, header
label_desc: Use image node_id 2 for calling a global function with example usage: shape_based_slice_interpolation(img, dim, nslices) and returns: out