code: def idx_affine_coord(idx, affine):
      """Compute coordinates from a set of indexes and an affine transform
  
      Parameters
      ----------
      idx:array of shape (n_samples, dim), type int
          indexes of certain positions in a nd space
      affine: (n+1, n+1) matrix,
              affine transform that maps the mask points to some embedding space
  
      Returns
      -------
      coords: array of shape(sum(mask>0), n),
              the computed coordinates
  
      """
      size = idx.shape[0]
      hidx = np.hstack((idx, np.ones((size, 1))))
      coord = np.dot(hidx, affine.T)[:, 0:-1]
      return coord
  
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 6 for calling a global function with example usage: idx_affine_coord(idx, affine) and returns: coord