Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix return_error='always' behavior in phase_cross_correlation #549

Merged
merged 3 commits into from
Apr 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import itertools
import math
import warnings

import cupy as cp
import cupyx.scipy.ndimage as ndi
Expand Down Expand Up @@ -220,7 +221,7 @@ def phase_cross_correlation(reference_image, moving_image, *,
this parameter is set to ``True``, the *real* space cross-correlation
is computed for each possible shift, and the shift with the highest
cross-correlation within the overlapping area is returned.
return_error : bool, optional
return_error : bool, {"always"}, optional
Returns error and phase difference if "always" is given. If False, or
either ``reference_mask`` or ``moving_mask`` are given, only the shift
is returned.
Expand Down Expand Up @@ -253,10 +254,14 @@ def phase_cross_correlation(reference_image, moving_image, *,
the axis order of the input array.
error : float
Translation invariant normalized RMS error between
``reference_image`` and ``moving_image``.
``reference_image`` and ``moving_image``. For masked cross-correlation
this error is not available and NaN is returned if ``return_error``
is "always".
phasediff : float
Global phase difference between the two images (should be
zero if images are non-negative).
zero if images are non-negative). For masked cross-correlation
this phase difference is not available and NaN is returned if
``return_error`` is "always".

Notes
-----
Expand Down Expand Up @@ -294,10 +299,25 @@ def phase_cross_correlation(reference_image, moving_image, *,
Pattern Recognition, pp. 2918-2925 (2010).
:DOI:`10.1109/CVPR.2010.5540032`
"""
def warn_return_error():
warnings.warn(
"In scikit-image 0.22, phase_cross_correlation will start "
"returning a tuple or 3 items (shift, error, phasediff) always. "
"To enable the new return behavior and silence this warning, use "
"return_error='always'.",
category=FutureWarning,
stacklevel=3,
)

if (reference_mask is not None) or (moving_mask is not None):
return _masked_phase_cross_correlation(reference_image, moving_image,
reference_mask, moving_mask,
overlap_ratio)
shift = _masked_phase_cross_correlation(reference_image, moving_image,
reference_mask, moving_mask,
overlap_ratio)
if return_error == "always":
return shift, np.nan, np.nan
else:
warn_return_error()
return shift

# images must be the same shape
if reference_image.shape != moving_image.shape:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,12 @@ def test_mismatch_offsets_size():
)
def test_disambiguate_2d(shift0, shift1):
image = cp.array(eagle()[500:, 900:]) # use a highly textured image region

# Protect against some versions of scikit-image + imagio loading as
# RGB instead of grayscale.
if image.ndim == 3:
image = image[..., 0]

shift = (shift0, shift1)
origin0 = []
for s in shift:
Expand Down