code: def _check_shape_compatibility(img1, img2, dim=None):
      """Check that shapes match for dimensions going from 0 to dim-1.
  
      Parameters
      ----------
      img1 : Niimg-like object
          See :ref:`extracting_data`.
          Image to extract the data from.
  
      img2 : Niimg-like object, optional
          See :ref:`extracting_data`.
          Contains map or mask.
  
      dim : :obj:`int`, optional
          Integer slices a mask for a specific dimension.
  
      """
      if dim is None:
          img2 = _utils.check_niimg_3d(img2)
          if img1.shape[:3] != img2.shape:
              raise ValueError("Images have incompatible shapes.")
      elif img1.shape[:dim] != img2.shape[:dim]:
          raise ValueError("Images have incompatible shapes.")
  
file_path: nilearn/nilearn/regions/signal_extraction.py
imports: import warnings
  import numpy
  from nibabel import Nifti1Image
  from scipy import linalg, ndimage
  from ..None import _utils, masking
  from .._utils.niimg import safe_get_data
  from ..image import new_img_like
label_desc: Use image node_id 1 for calling a global function with example usage: _check_shape_compatibility(img1, img2, dim) without return types