rank, connectivity) |
>>> print generate_binary_structure(2, 1) [[0 1 0] [1 1 1] [0 1 0]] >>> print generate_binary_structure(2, 2) [[1 1 1] [1 1 1] [1 1 1]]
Most binary morphology functions can be expressed in terms of the basic operations erosion and dilation:
input, structure=None, iterations=1, mask=None, output=None, border_value=0, origin=0) |
input, structure=None, iterations=1, mask=None, output=None, border_value=0, origin=0) |
Here is an example of using binary_dilation to find all elements that touch the border, by repeatedly dilating an empty array from the border using the data array as the mask:
>>> struct = array([[0, 1, 0], [1, 1, 1], [0, 1, 0]]) >>> a = array([[1,0,0,0,0], [1,1,0,1,0], [0,0,1,1,0], [0,0,0,0,0]]) >>> print a [[1 0 0 0 0] [1 1 0 1 0] [0 0 1 1 0] [0 0 0 0 0]] >>> print binary_dilation(zeros(a.shape), struct, -1, a, border_value=1) [[1 0 0 0 0] [1 1 0 0 0] [0 0 0 0 0] [0 0 0 0 0]]
The binary_erosion and binary_dilation functions both have an iterations parameter which allows the erosion or dilation to be repeated a number of times. Repeating an erosion or a dilation with a given structure n times is equivalent to an erosion or a dilation with a structure that is n-1 times dilated with itself. A function is provided that allows the calculation of a structure that is dilated a number of times with itself:
structure, iterations, origin=None) |
>>> struct = generate_binary_structure(2, 1) >>> print struct [[0 1 0] [1 1 1] [0 1 0]] >>> print iterate_structure(struct, 2) [[0 0 1 0 0] [0 1 1 1 0] [1 1 1 1 1] [0 1 1 1 0] [0 0 1 0 0]]
>>> print iterate_structure(struct, 2, -1) (array([[0, 0, 1, 0, 0], [0, 1, 1, 1, 0], [1, 1, 1, 1, 1], [0, 1, 1, 1, 0], [0, 0, 1, 0, 0]], type=Bool), [-2, -2])
Other morphology operations can be defined in terms of erosion and d dilation. Following functions provide a few of these operations for convenience:
input, structure=None, iterations=1, output=None, origin=0) |
input, structure=None, iterations=1, output=None, origin=0) |
input, structure = None, output = None, origin = 0) |
input, structure1=None, structure2=None, output=None, origin1=0, origin2=None) |
Send comments to the NumArray community.