code: def _disambiguate_shift(reference_image, moving_image, shift):
      """Determine the correct real-space shift based on periodic shift.
  
      When determining a translation shift from phase cross-correlation in
      Fourier space, the shift is only correct to within a period of the image
      size along each axis, resulting in $2^n$ possible shifts, where $n$ is the
      number of dimensions of the image. This function checks the
      cross-correlation in real space for each of those shifts, and returns the
      one with the highest cross-correlation.
  
      The strategy we use is to perform the shift on the moving image *using the
      'grid-wrap' mode* in `scipy.ndimage`. The moving image's original borders
      then define $2^n$ quadrants, which we cross-correlate with the reference
      image in turn using slicing. The entire operation is thus $O(2^n + m)$,
      where $m$ is the number of pixels in the image (and typically dominates).
  
      Parameters
      ----------
      reference_image : numpy array
          The reference (non-moving) image.
      moving_image : numpy array
          The moving image: applying the shift to this image overlays it on the
          reference image. Must be the same shape as the reference image.
      shift : ndarray
          The shift to apply to each axis of the moving image, *modulo* image
          size. The length of ``shift`` must be equal to ``moving_image.ndim``.
  
      Returns
      -------
      real_shift : ndarray
          The shift disambiguated in real space.
      """
      shape = reference_image.shape
      positive_shift = [shift_i % s for shift_i, s in zip(shift, shape)]
      negative_shift = [
          shift_i - s for shift_i, s in zip(positive_shift, shape)
      ]
      subpixel = np.any(np.array(shift) % 1 != 0)
      interp_order = 3 if subpixel else 0
      shifted = ndi.shift(
          moving_image, shift, mode="grid-wrap", order=interp_order
      )
      indices = np.round(positive_shift).astype(int)
      splits_per_dim = [(slice(0, i), slice(i, None)) for i in indices]
      max_corr = -1.0
      max_slice = None
      for test_slice in itertools.product(*splits_per_dim):
          reference_tile = np.reshape(reference_image[test_slice], -1)
          moving_tile = np.reshape(shifted[test_slice], -1)
          corr = -1.0
          if reference_tile.size > 2:
              # In the case of zero std, np.corrcoef returns NaN and warns
              # about division by zero. This is expected and handled below.
              with warnings.catch_warnings():
                  warnings.filterwarnings(
                      "ignore", category=RuntimeWarning
                  )
                  corr = np.corrcoef(reference_tile, moving_tile)[0, 1]
          if corr > max_corr:
              max_corr = corr
              max_slice = test_slice
      if max_slice is None:
          warnings.warn(
              f"Could not determine real-space shift for periodic shift {shift!r} "
              f"as requested by `disambiguate=True` (disambiguation is degenerate).",
              stacklevel=3,
          )
          return shift
      real_shift_acc = []
      for sl, pos_shift, neg_shift in zip(
          max_slice, positive_shift, negative_shift
      ):
          real_shift_acc.append(
              pos_shift if sl.stop is None else neg_shift
          )
  
      return np.array(real_shift_acc)
  
file_path: scikit-image/skimage/registration/_phase_cross_correlation.py
imports: import itertools
  import warnings
  import numpy
  from scipy.fft import fftn, ifftn, fftfreq
  from scipy import ndimage
  from ._masked_phase_cross_correlation import _masked_phase_cross_correlation
label_desc: Use image node_id 4 for calling a global function with example usage: _disambiguate_shift(reference_image, moving_image, shift) and returns: np, shift