mirror of
https://github.com/wassname/scikit-image.git
synced 2026-08-17 11:26:12 +08:00
Merge pull request #1217 from jni/morpho-out
Allow discontiguous out arrays in `skimage.morphology.grey`
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user