code: def crop_img(
      img, rtol=1e-8, copy=True, pad=True, return_offset=False
  ):
      """Crops an image as much as possible.
  
      Will crop `img`, removing as many zero entries as possible without
      touching non-zero entries.
      Will leave one :term:`voxel` of zero padding
      around the obtained non-zero area in order
      to avoid sampling issues later on.
  
      Parameters
      ----------
      img : Niimg-like object
          Image to be cropped (see :ref:`extracting_data` for a detailed
          description of the valid input types).
  
      rtol : :obj:`float`, default=1e-8
          relative tolerance (with respect to maximal absolute value of the
          image), under which values are considered negligeable and thus
          croppable.
  
      copy : :obj:`bool`, default=True
          Specifies whether cropped data is copied or not.
  
      pad : :obj:`bool`, default=True
          Toggles adding 1-voxel of 0s around the border.
  
      return_offset : :obj:`bool`, default=False
          Specifies whether to return a tuple of the removed padding.
  
      Returns
      -------
      Niimg-like object or :obj:`tuple`
          Cropped version of the input image and, if `return_offset=True`,
          a tuple of tuples representing the number of voxels
          removed (before, after) the cropped volumes, i.e.:
          *[(x1_pre, x1_post), (x2_pre, x2_post), ..., (xN_pre, xN_post)]*
  
      """
      img = check_niimg(img)
      data = get_data(img)
      infinity_norm = max(-data.min(), data.max())
      passes_threshold = np.logical_or(
          data < -rtol * infinity_norm, data > rtol * infinity_norm
      )
  
      if data.ndim == 4:
          passes_threshold = np.any(passes_threshold, axis=-1)
      coords = np.array(np.where(passes_threshold))
  
      # Sets full range if no data are found along the axis
      if coords.shape[1] == 0:
          start, end = [0, 0, 0], list(data.shape)
      else:
          start = coords.min(axis=1)
          end = coords.max(axis=1) + 1
  
      # pad with one voxel to avoid resampling problems
      if pad:
          start = np.maximum(start - 1, 0)
          end = np.minimum(end + 1, data.shape[:3])
  
      slices = [slice(s, e) for s, e in zip(start, end)][:3]
      cropped_im = _crop_img_to(img, slices, copy=copy)
      return (
          (cropped_im, tuple(slices)) if return_offset else cropped_im
      )
  
imports: import collections.abc
  import copy
  import itertools
  import warnings
  import nibabel
  import numpy
  from joblib import Memory, Parallel, delayed
  from scipy.ndimage import gaussian_filter1d, generate_binary_structure, label
  from scipy.stats import scoreatpercentile
  from ..None import signal
  from .._utils import _repr_niimgs, as_ndarray, check_niimg, check_niimg_3d, check_niimg_4d, fill_doc
  from .._utils.exceptions import DimensionError
  from .._utils.helpers import rename_parameters, stringify_path
  from .._utils.niimg import _get_data, safe_get_data
  from .._utils.niimg_conversions import _index_img, check_same_fov, iter_check_niimg
  from .._utils.param_validation import check_threshold
  from .._utils.path_finding import resolve_globbing
label_desc: Use image node_id 7 for calling a global function with example usage: crop_img(img, rtol, copy, pad, return_offset) and returns: unknown