mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-06 05:16:40 +08:00
Change binary morphology functions to output numpy.bool dtype
This commit is contained in:
@@ -49,7 +49,7 @@ def binary_erosion(image, selem=None, out=None):
|
||||
ndimage.convolve(binary, selem, mode='constant', cval=1, output=conv)
|
||||
|
||||
if out is None:
|
||||
out = conv
|
||||
out = np.empty_like(conv, dtype=np.bool)
|
||||
return np.equal(conv, selem_sum, out=out)
|
||||
|
||||
|
||||
@@ -98,7 +98,7 @@ def binary_dilation(image, selem=None, out=None):
|
||||
ndimage.convolve(binary, selem, mode='constant', cval=0, output=conv)
|
||||
|
||||
if out is None:
|
||||
out = conv
|
||||
out = np.empty_like(conv, dtype=np.bool)
|
||||
return np.not_equal(conv, 0, out=out)
|
||||
|
||||
|
||||
|
||||
@@ -110,5 +110,45 @@ def test_3d_fallback_cube_selem():
|
||||
new_image = function(image, cube)
|
||||
yield testing.assert_array_equal, new_image, image
|
||||
|
||||
def test_binary_output_2d():
|
||||
image = np.zeros((9, 9), np.uint16)
|
||||
image[2:-2, 2:-2] = 2**14
|
||||
image[3:-3, 3:-3] = 2**15
|
||||
image[4, 4] = 2**16-1
|
||||
|
||||
bin_opened = binary.binary_opening(image)
|
||||
bin_closed = binary.binary_closing(image)
|
||||
|
||||
int_opened = np.empty_like(image, dtype=np.uint8)
|
||||
int_closed = np.empty_like(image, dtype=np.uint8)
|
||||
binary.binary_opening(image, out=int_opened)
|
||||
binary.binary_closing(image, out=int_closed)
|
||||
|
||||
testing.assert_equal(bin_opened.dtype, np.bool)
|
||||
testing.assert_equal(bin_closed.dtype, np.bool)
|
||||
|
||||
testing.assert_equal(int_opened.dtype, np.uint8)
|
||||
testing.assert_equal(int_closed.dtype, np.uint8)
|
||||
|
||||
def test_binary_output_3d():
|
||||
image = np.zeros((9, 9, 9), np.uint16)
|
||||
image[2:-2, 2:-2, 2:-2] = 2**14
|
||||
image[3:-3, 3:-3, 3:-3] = 2**15
|
||||
image[4, 4, 4] = 2**16-1
|
||||
|
||||
bin_opened = binary.binary_opening(image)
|
||||
bin_closed = binary.binary_closing(image)
|
||||
|
||||
int_opened = np.empty_like(image, dtype=np.uint8)
|
||||
int_closed = np.empty_like(image, dtype=np.uint8)
|
||||
binary.binary_opening(image, out=int_opened)
|
||||
binary.binary_closing(image, out=int_closed)
|
||||
|
||||
testing.assert_equal(bin_opened.dtype, np.bool)
|
||||
testing.assert_equal(bin_closed.dtype, np.bool)
|
||||
|
||||
testing.assert_equal(int_opened.dtype, np.uint8)
|
||||
testing.assert_equal(int_closed.dtype, np.uint8)
|
||||
|
||||
if __name__ == '__main__':
|
||||
testing.run_module_suite()
|
||||
|
||||
Reference in New Issue
Block a user