code: def plot_img_comparison(
      ref_imgs,
      src_imgs,
      masker,
      plot_hist=True,
      log=True,
      ref_label="image set 1",
      src_label="image set 2",
      output_dir=None,
      axes=None,
  ):
      """Create plots to compare two lists of images and measure correlation.
  
      The first plot displays linear correlation between :term:`voxel` values.
      The second plot superimposes histograms to compare values distribution.
  
      Parameters
      ----------
      ref_imgs : nifti_like
          Reference images.
  
      src_imgs : nifti_like
          Source images.
  
      masker : NiftiMasker object
          Mask to be used on data.
  
      plot_hist : Boolean, default=True
          If True then histograms of each img in ref_imgs will be plotted
          along-side the histogram of the corresponding image in src_imgs.
  
      log : Boolean, default=True
          Passed to plt.hist.
  
      ref_label : str, default='image set 1'
          Name of reference images.
  
      src_label : str, default='image set 2'
          Name of source images.
  
      output_dir : string, optional
          Directory where plotted figures will be stored.
  
      axes : list of two matplotlib Axes objects, optional
          Can receive a list of the form [ax1, ax2] to render the plots.
          By default new axes will be created.
  
      Returns
      -------
      corrs : numpy.ndarray
          Pearson correlation between the images.
  
      """
      # note: doesn't work with 4d images;
      # when plot_hist is False creates two empty axes and doesn't plot anything
      corrs = []
      for i, (ref_img, src_img) in enumerate(zip(ref_imgs, src_imgs)):
          if axes is None:
              _, (ax1, ax2) = plt.subplots(1, 2, figsize=(12, 5))
          else:
              (ax1, ax2) = axes
          ref_data = masker.transform(ref_img).ravel()
          src_data = masker.transform(src_img).ravel()
          if ref_data.shape != src_data.shape:
              warnings.warn("Images are not shape-compatible")
              return
  
          corr = stats.pearsonr(ref_data, src_data)[0]
          corrs.append(corr)
  
          if plot_hist:
              ax1.scatter(
                  ref_data,
                  src_data,
                  label=f"Pearsonr: {corr:.2f}",
                  c="g",
                  alpha=0.6,
              )
              x = np.linspace(*ax1.get_xlim(), num=100)
              ax1.plot(x, x, linestyle="--", c="k")
              ax1.grid("on")
              ax1.set_xlabel(ref_label)
              ax1.set_ylabel(src_label)
              ax1.legend(loc="best")
  
              ax2.hist(
                  ref_data,
                  alpha=0.6,
                  bins=128,
                  log=log,
                  label=ref_label,
              )
              ax2.hist(
                  src_data,
                  alpha=0.6,
                  bins=128,
                  log=log,
                  label=src_label,
              )
              ax2.set_title("Histogram of imgs values")
              ax2.grid("on")
              ax2.legend(loc="best")
  
              if output_dir is not None:
                  if not os.path.exists(output_dir):
                      os.makedirs(output_dir)
                  plt.savefig(
                      os.path.join(output_dir, f"{int(i):04}.png")
                  )
  
          plt.tight_layout()
  
      return corrs
  
imports: import collections.abc
  import functools
  import numbers
  import os
  import warnings
  import matplotlib
  import matplotlib.pyplot
  import numpy
  from matplotlib import gridspec
  from matplotlib.colors import LinearSegmentedColormap
  from nibabel.spatialimages import SpatialImage
  from scipy import stats
  from scipy.ndimage import binary_fill_holes
  from nilearn.image.resampling import reorder_img
  from nilearn.maskers import NiftiMasker
  from nilearn.plotting.displays import get_projector, get_slicer
  from nilearn.plotting.displays._slicers import _get_cbar_ticks
  from ..None import _utils
  from .._utils import compare_version, fill_doc
  from .._utils.extmath import fast_abs_percentile
  from .._utils.ndimage import get_border_data
  from .._utils.niimg import safe_get_data
  from .._utils.numpy_conversions import as_ndarray
  from .._utils.param_validation import check_threshold
  from ..datasets import load_mni152_template
  from ..image import get_data, iter_img, math_img, new_img_like, resample_to_img
  from ..masking import apply_mask, compute_epi_mask
  from ..signal import clean
  from .None import cm
label_desc: Use image node_id 17 for calling a global function with example usage: plot_img_comparison(ref_imgs, src_imgs, masker, plot_hist, log, ref_label, src_label, output_dir, axes) and returns: corrs