diff --git a/skimage/restoration/tests/test_unwrap.py b/skimage/restoration/tests/test_unwrap.py index 4353dc20..f5ff2c76 100644 --- a/skimage/restoration/tests/test_unwrap.py +++ b/skimage/restoration/tests/test_unwrap.py @@ -186,5 +186,22 @@ def test_unwrap_2d_all_masked(): assert unwrap[0, 0] == 0 +def test_unwrap_3d_all_masked(): + # all elements masked + image = np.ma.zeros((10, 10, 10)) + image[:] = np.ma.masked + unwrap = unwrap_phase(image) + assert np.ma.isMaskedArray(unwrap) + assert np.all(unwrap.mask) + + # 1 unmasked element, still zero edges + image = np.ma.zeros((10, 10, 10)) + image[:] = np.ma.masked + image[0, 0, 0] = 0 + unwrap = unwrap_phase(image) + assert np.ma.isMaskedArray(unwrap) + assert np.sum(unwrap.mask) == 999 # all but one masked + assert unwrap[0, 0, 0] == 0 + if __name__ == "__main__": run_module_suite() diff --git a/skimage/restoration/unwrap_3d_ljmu.c b/skimage/restoration/unwrap_3d_ljmu.c index be47f926..fdd9847a 100644 --- a/skimage/restoration/unwrap_3d_ljmu.c +++ b/skimage/restoration/unwrap_3d_ljmu.c @@ -1136,9 +1136,11 @@ void unwrap3D(double *wrapped_volume, double *unwrapped_volume, ¶ms); normalEDGEs(voxel, edge, volume_width, volume_height, volume_depth, ¶ms); - // sort the EDGEs depending on their reiability. The VOXELs with higher - // relibility (small value) first - quicker_sort(edge, edge + params.no_of_edges - 1); + if (params.no_of_edges != 0) { + // sort the EDGEs depending on their reiability. The VOXELs with higher + // relibility (small value) first + quicker_sort(edge, edge + params.no_of_edges - 1); + } // gather VOXELs into groups gatherVOXELs(edge, ¶ms);