Skip to content

Commit

Permalink
In phase_cross_corr, catch expected runtime warning.
Browse files Browse the repository at this point in the history
  • Loading branch information
m-albert committed Sep 22, 2023
1 parent de8f04a commit 3de6abb
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions skimage/registration/_phase_cross_correlation.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,14 @@ def _disambiguate_shift(reference_image, moving_image, shift):
moving_tile = np.reshape(shifted[test_slice], -1)
corr = -1.0
if reference_tile.size > 2:
corr = np.corrcoef(reference_tile, moving_tile)[0, 1]
if corr > max_corr:
# In the case of zero std, np.corrcoef returns nan and warns
# about zero division. This is expected and handled below.
# To avoid performing a computationally expensive check for
# zero std, we catch the warning.
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=RuntimeWarning)
corr = np.corrcoef(reference_tile, moving_tile)[0, 1]
if corr > max_corr: # False in case corr==nan
max_corr = corr
max_slice = test_slice
real_shift_acc = []
Expand Down

0 comments on commit 3de6abb

Please sign in to comment.