class_docstr: Particular instance of StructuredDomain, that receives
  3 additional variables:
  affine: array of shape (dim+1, dim+1),
          affine transform that maps points to a coordinate system
  shape: dim-tuple,
         shape of the domain
  ijk: array of shape(size, dim), int
       grid coordinates of the points
  
  This is to allow easy conversion to images when dim==3,
  and for compatibility with previous classes
class_docstr_tok: ["Particular","instance","of","StructuredDomain",",","that","receives","3","additional","variables",":","affine",":","array","of","shape","(","dim+1",",","dim+1",")",",","affine","transform","that","maps","points","to","a","coordinate","system","shape",":","dim-tuple",",","shape","of","the","domain","ijk",":","array","of","shape","(","size",",","dim",")",",","int","grid","coordinates","of","the","points","This","is","to","allow","easy","conversion","to","images","when","dim==3",",","and","for","compatibility","with","previous","classes"]
docstr: Write itself as a binary image, and returns it
  
  Parameters
  ----------
  path: string, path of the output image, if any
  data: array of shape self.size,
        data to put in the nonzer-region of the image
code: def to_image(self, path=None, data=None):
      """Write itself as a binary image, and returns it
  
      Parameters
      ----------
      path: string, path of the output image, if any
      data: array of shape self.size,
            data to put in the nonzer-region of the image
  
      """
      if data is None:
          wdata = np.zeros(self.shape, np.int8)
      else:
          wdata = np.zeros(self.shape, data.dtype)
      wdata[self.ijk[:, 0], self.ijk[:, 1], self.ijk[:, 2]] = 1
      if data is not None:
          if data.size != self.size:
              raise ValueError("incorrect data size")
          wdata[wdata > 0] = data
  
      nim = Nifti1Image(wdata, self.affine)
      get_header(nim)[
          "descrip"
      ] = f"mask image representing domain {self.id}"
      if path is not None:
          save(nim, path)
      return nim
  
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 3 for calling the NDGridDomain obj's underlying member method code with example usage: obj.to_image(path, data) and returns: nim