@@ -24,6 +24,16 @@ def cell3d_image():
2424 return np .ascontiguousarray (data .cells3d ()[30 :48 , 0 , 20 :36 , 20 :32 ])
2525
2626
27+ gray_morphology_funcs = (
28+ gray .erosion ,
29+ gray .dilation ,
30+ gray .opening ,
31+ gray .closing ,
32+ gray .white_tophat ,
33+ gray .black_tophat ,
34+ )
35+
36+
2737class TestMorphology :
2838 # These expected outputs were generated with skimage v0.22.0 + PR #6695
2939 # using:
@@ -34,14 +44,6 @@ class TestMorphology:
3444 # np.savez_compressed('gray_morph_output.npz', **output)
3545
3646 def _build_expected_output (self ):
37- funcs = (
38- gray .erosion ,
39- gray .dilation ,
40- gray .opening ,
41- gray .closing ,
42- gray .white_tophat ,
43- gray .black_tophat ,
44- )
4547 footprints_2D = (
4648 footprints .square ,
4749 footprints .diamond ,
@@ -56,7 +58,7 @@ def _build_expected_output(self):
5658 output = {}
5759 for n in range (1 , 4 ):
5860 for strel in footprints_2D :
59- for func in funcs :
61+ for func in gray_morphology_funcs :
6062 key = f'{ strel .__name__ } _{ n } _{ func .__name__ } '
6163 output [key ] = func (image , strel (n ))
6264
@@ -89,6 +91,19 @@ def test_gray_opening_anti_extensive(self):
8991 result_ignore = gray .opening (img , footprint = footprint , mode = "ignore" )
9092 assert np .all (result_ignore <= img )
9193
94+ @pytest .mark .parametrize ("func" , gray_morphology_funcs )
95+ @pytest .mark .parametrize ("mode" , gray ._SUPPORTED_MODES )
96+ def test_supported_mode (self , func , mode ):
97+ img = np .ones ((10 , 10 ))
98+ func (img , mode = mode )
99+
100+ @pytest .mark .parametrize ("func" , gray_morphology_funcs )
101+ @pytest .mark .parametrize ("mode" , ["" , "symmetric" , 3 , None ])
102+ def test_unsupported_mode (self , func , mode ):
103+ img = np .ones ((10 , 10 ))
104+ with pytest .raises (ValueError , match = "unsupported mode" ):
105+ func (img , mode = mode )
106+
92107
93108class TestEccentricStructuringElements :
94109 def setup_class (self ):
0 commit comments