diff --git a/skimage/registration/_phase_cross_correlation.py b/skimage/registration/_phase_cross_correlation.py index c990ce8e3c7..f904f1707da 100644 --- a/skimage/registration/_phase_cross_correlation.py +++ b/skimage/registration/_phase_cross_correlation.py @@ -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 = []