From de01ea56ae0fdf451bb417d60b8545c065ddaa1c Mon Sep 17 00:00:00 2001 From: Jonathan Helmus Date: Wed, 21 Jan 2015 16:23:50 -0600 Subject: [PATCH] unwrap_phase returns masked array when image is masked With commit e3b84ed the unwrap_phase function would always return an ndarray even when image was masked. This restores the pre-e3b84ed behavior of returning a masked array when the image is masked. --- skimage/restoration/tests/test_unwrap.py | 1 + skimage/restoration/unwrap.py | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/skimage/restoration/tests/test_unwrap.py b/skimage/restoration/tests/test_unwrap.py index 979cd80c..ca4cfe32 100644 --- a/skimage/restoration/tests/test_unwrap.py +++ b/skimage/restoration/tests/test_unwrap.py @@ -131,6 +131,7 @@ def test_mask(): # The end of the unwrapped array should have value equal to the # endpoint of the unmasked ramp assert_array_almost_equal_nulp(image_unwrapped[:, -1], image[i, -1]) + assert np.ma.isMaskedArray(image_unwrapped) # Same tests, but forcing use of the 3D unwrapper by reshaping with expected_warnings(['length 1 dimension']): diff --git a/skimage/restoration/unwrap.py b/skimage/restoration/unwrap.py index 6dd7c7ef..36fe0d9d 100644 --- a/skimage/restoration/unwrap.py +++ b/skimage/restoration/unwrap.py @@ -89,11 +89,11 @@ def unwrap_phase(image, wrap_around=False, seed=None): if np.ma.isMaskedArray(image): mask = np.require(np.ma.getmaskarray(image), np.uint8, ['C']) - image = np.ma.getdata(image) else: mask = np.zeros_like(image, dtype=np.uint8, order='C') - image_not_masked = np.asarray(image, dtype=np.double, order='C') + image_not_masked = np.asarray( + np.ma.getdata(image), dtype=np.double, order='C') image_unwrapped = np.empty_like(image, dtype=np.double, order='C') if image.ndim == 1: