Merge pull request #1217 from jni/morpho-out

Allow discontiguous out arrays in `skimage.morphology.grey`
This commit is contained in:
Steven Silvester
2014-11-05 20:35:56 -06:00
2 changed files with 22 additions and 5 deletions
-4
View File
@@ -49,8 +49,6 @@ def _dilate(np.uint8_t[:, :] image,
image = np.ascontiguousarray(image)
if out is None:
out = np.zeros((rows, cols), dtype=np.uint8)
else:
out = np.ascontiguousarray(out)
cdef Py_ssize_t r, c, rr, cc, s, value, local_max
@@ -125,8 +123,6 @@ def _erode(np.uint8_t[:, :] image,
image = np.ascontiguousarray(image)
if out is None:
out = np.zeros((rows, cols), dtype=np.uint8)
else:
out = np.ascontiguousarray(out)
cdef int r, c, rr, cc, s, value, local_min
+22 -1
View File
@@ -6,7 +6,6 @@ from scipy import ndimage
import skimage
from skimage import data_dir
from skimage.util import img_as_bool
from skimage.morphology import grey, selem
@@ -247,5 +246,27 @@ def test_inplace():
testing.assert_raises(NotImplementedError, f, image, selem, out=out)
def test_discontiguous_out_array():
image = np.array([[5, 6, 2],
[7, 2, 2],
[3, 5, 1]], np.uint8)
out_array_big = np.zeros((5, 5), np.uint8)
out_array = out_array_big[::2, ::2]
expected_dilation = np.array([[7, 0, 6, 0, 6],
[0, 0, 0, 0, 0],
[7, 0, 7, 0, 2],
[0, 0, 0, 0, 0],
[7, 0, 5, 0, 5]], np.uint8)
expected_erosion = np.array([[5, 0, 2, 0, 2],
[0, 0, 0, 0, 0],
[2, 0, 2, 0, 1],
[0, 0, 0, 0, 0],
[3, 0, 1, 0, 1]], np.uint8)
grey.dilation(image, out=out_array)
testing.assert_array_equal(out_array_big, expected_dilation)
grey.erosion(image, out=out_array)
testing.assert_array_equal(out_array_big, expected_erosion)
if __name__ == '__main__':
testing.run_module_suite()