code: def _check_shape_and_affine_compatibility(img1, img2=None, dim=None):
      """Validate shapes and affines of 2 images.
  
      Check that the provided images:
          - have the same shape
          - have the same affine matrix.
  
      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.
  
      Returns
      -------
      non_empty : :obj:`bool`,
          Is only true for non-empty img.
  
      """
      if img2 is None:
          return False
  
      _check_shape_compatibility(img1, img2, dim=dim)
  
      if dim is None:
          img2 = _utils.check_niimg_3d(img2)
      _check_affine_equality(img1, img2)
  
      return True
  
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 3 for calling a global function with example usage: _check_shape_and_affine_compatibility(img1, img2, dim) and returns: True, False