code: def autocrop_img(img, bg_color):
      red, green, blue = bg_color
  
      outline = (
          (img[..., 0] != red)
          + (img[..., 1] != green)
          + (img[..., 2] != blue)
      )
      outline_x = outline.sum(axis=0)
      outline_y = outline.sum(axis=1)
  
      outline_x = np.where(outline_x)[0]
      outline_y = np.where(outline_y)[0]
  
      if len(outline_x) == 0:
          return img
      else:
          x_min = outline_x.min()
          x_max = outline_x.max()
      if len(outline_y) == 0:
          return img
      else:
          y_min = outline_y.min()
          y_max = outline_y.max()
      return img[y_min:y_max, x_min:x_max]
  
file_path: nipy/nipy/labs/viz_tools/maps_3d.py
imports: import os
  import tempfile
  import numpy
  from scipy import stats
  from .anat_cache import _AnatCache, mni_sform, mni_sform_inv
  from .coord_tools import coord_transform
label_desc: Use image node_id 2 for calling a global function with example usage: autocrop_img(img, bg_color) and returns: img, img, img