mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-17 11:32:45 +08:00
Add 3d-fallback tests for binary functions
This commit is contained in:
@@ -4,6 +4,7 @@ from numpy import testing
|
||||
from skimage import data, color
|
||||
from skimage.util import img_as_bool
|
||||
from skimage.morphology import binary, grey, selem
|
||||
from scipy import ndimage
|
||||
|
||||
|
||||
lena = color.rgb2gray(data.lena())
|
||||
@@ -86,5 +87,28 @@ def test_default_selem():
|
||||
im_test = function(image)
|
||||
yield testing.assert_array_equal, im_expected, im_test
|
||||
|
||||
def test_3d_fallback_default_selem():
|
||||
# 3x3x3 cube inside a 7x7x7 image:
|
||||
image = np.zeros((7, 7, 7), np.bool)
|
||||
image[2:-2, 2:-2, 2:-2] = 1
|
||||
|
||||
opened = binary.binary_opening(image)
|
||||
|
||||
# expect a "hyper-cross" centered in the 5x5x5:
|
||||
image_expected = np.zeros((7, 7, 7), dtype=bool)
|
||||
image_expected[2:5, 2:5, 2:5] = ndimage.generate_binary_structure(3, 1)
|
||||
testing.assert_array_equal(opened, image_expected)
|
||||
|
||||
def test_3d_fallback_cube_selem():
|
||||
# 3x3x3 cube inside a 7x7x7 image:
|
||||
image = np.zeros((7, 7, 7), np.bool)
|
||||
image[2:-2, 2:-2, 2:-2] = 1
|
||||
|
||||
cube = np.ones((3, 3, 3), dtype=np.uint8)
|
||||
|
||||
for function in [binary.binary_closing, binary.binary_opening]:
|
||||
new_image = function(image, cube)
|
||||
yield testing.assert_array_equal, new_image, image
|
||||
|
||||
if __name__ == '__main__':
|
||||
testing.run_module_suite()
|
||||
|
||||
@@ -2,6 +2,7 @@ import os.path
|
||||
|
||||
import numpy as np
|
||||
from numpy import testing
|
||||
from scipy import ndimage
|
||||
|
||||
import skimage
|
||||
from skimage import data_dir
|
||||
@@ -147,19 +148,19 @@ def test_3d_fallback_default_selem():
|
||||
image = np.zeros((7, 7, 7), np.bool)
|
||||
image[2:-2, 2:-2, 2:-2] = 1
|
||||
|
||||
opened = morphology.opening(image)
|
||||
opened = grey.opening(image)
|
||||
|
||||
# expect a "hyper-cross" centered in the 5x5x5:
|
||||
image_expected = np.zeros((7, 7, 7), dtype=bool)
|
||||
image_expected[2:5, 2:5, 2:5] = ndimage.generate_binary_structure(3, 1)
|
||||
testing.assert_array_equal(opened, image_expected)
|
||||
|
||||
def test_3d_fallback_default_selem():
|
||||
def test_3d_fallback_cube_selem():
|
||||
# 3x3x3 cube inside a 7x7x7 image:
|
||||
image = np.zeros((7, 7, 7), np.bool)
|
||||
image[2:-2, 2:-2, 2:-2] = 1
|
||||
|
||||
cube = np.ones((3, 3, 3),dtype=np.uint8)
|
||||
cube = np.ones((3, 3, 3), dtype=np.uint8)
|
||||
|
||||
for function in [grey.closing, grey.opening]:
|
||||
new_image = function(image, cube)
|
||||
|
||||
Reference in New Issue
Block a user