File tree Expand file tree Collapse file tree 1 file changed +9
-7
lines changed
Expand file tree Collapse file tree 1 file changed +9
-7
lines changed Original file line number Diff line number Diff line change @@ -45,18 +45,20 @@ def __post_init__(self):
4545 ) # required with frozen objects
4646
4747 def _parse_connectivity (self , connectivity : int | np .ndarray ) -> np .ndarray :
48- if isinstance (connectivity , int ):
49- if connectivity not in (1 , 2 ):
48+ match connectivity :
49+ case np .ndarray ():
50+ return connectivity
51+ case 1 | 2 :
52+ return ndi .generate_binary_structure (2 , connectivity )
53+ case int (): # another integer
5054 msg = (
5155 f"Unsupported connectivity value: { connectivity } ."
5256 " Must be 1 or 2, or input a custom structure as array."
5357 )
5458 raise ValueError (msg )
55- return ndi .generate_binary_structure (2 , connectivity )
56- if isinstance (connectivity , np .ndarray ):
57- return connectivity
58- msg = f"Unsupported connectivity type: { type (connectivity )} . Must be an integer or numpy array."
59- raise ValueError (msg )
59+ case _:
60+ msg = f"Unsupported connectivity type: { type (connectivity )} . Must be an integer or numpy array."
61+ raise ValueError (msg )
6062
6163 def apply (self , mask : PixelMask ) -> PixelMask :
6264 """Identify connected regions in a PixelMask, filter them by size, and return a combined mask.
You can’t perform that action at this time.
0 commit comments