code: def get_mask_bounds(mask, affine):
      """Return the world-space bounds occupied by a mask given an affine.
  
      Notes
      -----
  
      The mask should have only one connect component.
  
      The affine should be diagonal or diagonal-permuted.
      """
      (xmin, xmax), (ymin, ymax), (zmin, zmax) = get_bounds(
          mask.shape, affine
      )
      slices = ndimage.find_objects(mask)
      if len(slices) == 0:
          warnings.warn("empty mask", stacklevel=2)
      else:
          x_slice, y_slice, z_slice = slices[0]
          x_width, y_width, z_width = mask.shape
          xmin, xmax = (
              xmin + x_slice.start * (xmax - xmin) / x_width,
              xmin + x_slice.stop * (xmax - xmin) / x_width,
          )
          ymin, ymax = (
              ymin + y_slice.start * (ymax - ymin) / y_width,
              ymin + y_slice.stop * (ymax - ymin) / y_width,
          )
          zmin, zmax = (
              zmin + z_slice.start * (zmax - zmin) / z_width,
              zmin + z_slice.stop * (zmax - zmin) / z_width,
          )
  
      return xmin, xmax, ymin, ymax, zmin, zmax
  
file_path: nipy/nipy/labs/viz_tools/coord_tools.py
imports: import warnings
  import numpy
  from scipy import ndimage, stats
  from ..datasets.transforms.affine_utils import get_bounds
  from ..mask import largest_cc
label_desc: Use image node_id 3 for calling a global function with example usage: get_mask_bounds(mask, affine) and returns: xmin,  xmax,  ymin,  ymax,  zmin,  zmax