def ball(radius, dtype=np.uint8):
 n = ((2 * radius) + 1)
 (Z, Y, X) = np.mgrid[(- radius):radius:(n * 1j), (- radius):radius:(n * 1j), (- radius):radius:(n * 1j)]
 s = (((X ** 2) + (Y ** 2)) + (Z ** 2))
 return np.array((s <= (radius * radius)), dtype=dtype)

def ball ( radius , dtype = np . uint8 ) : n = ( ( 2 * radius ) + 1 ) ( Z , Y , X ) = np . mgrid [ ( - radius ) : radius : ( n * 1j ) , ( - radius ) : radius : ( n * 1j ) , ( - radius ) : radius : ( n * 1j ) ] s = ( ( ( X ** 2 ) + ( Y ** 2 ) ) + ( Z ** 2 ) ) return np . array ( ( s <= ( radius * radius ) ) , dtype = dtype )
generates a ball-shaped structuring element .