diff --git a/skimage/exposure/tests/test_unwrap.py b/skimage/exposure/tests/test_unwrap.py index a465cd2c..1e1b0cd5 100644 --- a/skimage/exposure/tests/test_unwrap.py +++ b/skimage/exposure/tests/test_unwrap.py @@ -70,7 +70,10 @@ def check_wrap_around(ndim, axis): index_first = tuple([0] * ndim) index_last = tuple([-1 if n == axis else 0 for n in range(ndim)]) # unwrap the image without wrap around - image_unwrap_no_wrap_around = unwrap_phase(image_wrapped) + with warnings.catch_warnings(): + # We do not want warnings about length 1 dimensions + warnings.simplefilter("ignore") + image_unwrap_no_wrap_around = unwrap_phase(image_wrapped) print('endpoints without wrap_around:', image_unwrap_no_wrap_around[index_first], image_unwrap_no_wrap_around[index_last]) @@ -79,7 +82,10 @@ def check_wrap_around(ndim, axis): - image_unwrap_no_wrap_around[index_last]) > np.pi # unwrap the image with wrap around wrap_around = [n == axis for n in range(ndim)] - image_unwrap_wrap_around = unwrap_phase(image_wrapped, wrap_around) + with warnings.catch_warnings(): + # We do not want warnings about length 1 dimensions + warnings.simplefilter("ignore") + image_unwrap_wrap_around = unwrap_phase(image_wrapped, wrap_around) print('endpoints with wrap_around:', image_unwrap_wrap_around[index_first], image_unwrap_wrap_around[index_last]) diff --git a/skimage/exposure/unwrap.py b/skimage/exposure/unwrap.py index ab05bc5e..c43e263d 100644 --- a/skimage/exposure/unwrap.py +++ b/skimage/exposure/unwrap.py @@ -1,4 +1,5 @@ import numpy as np +import warnings from ._unwrap_2d import unwrap_2d from ._unwrap_3d import unwrap_3d @@ -53,6 +54,9 @@ def unwrap_phase(image, wrap_around=False): else: raise ValueError('wrap_around must be a bool or a sequence with ' 'length equal to the dimensionality of image') + if image.ndim == 3 and 1 in image.shape: + warnings.warn('image is 3D and has a length 1 dimension; consider ' + 'using a 2D array to use the 2D unwrapping algorithm') if np.ma.isMaskedArray(image): mask = np.require(image.mask, np.uint8, ['C'])