code: def grid_domain_from_image(mim, nn=18):
      """Return a NDGridDomain instance from the input mask image
  
      Parameters
      ----------
      mim: NiftiIImage instance, or string path toward such an image
           supposedly a mask (where is used to create the DD)
      nn: int, optional
          neighboring system considered from the image
          can be 6, 18 or 26
  
      Returns
      -------
      The corresponding NDGridDomain instance
  
      """
      if isinstance(mim, str):
          iim = load(mim)
      else:
          iim = mim
      return grid_domain_from_binary_array(
          iim.get_fdata(), get_affine(iim), nn
      )
  
imports: import numpy
  import scipy.sparse
  from nibabel import Nifti1Image, load, save
  from nipy.algorithms.graph import WeightedGraph, wgraph_from_3d_grid, wgraph_from_coo_matrix
  from nipy.io.nibcompat import get_affine, get_header
label_desc: Use image node_id 11 for calling a global function with example usage: grid_domain_from_image(mim, nn) and returns: grid_domain_from_binary_array