bundles / scipy latest / scipy / ndimage / _morphology / binary_opening
function
scipy.ndimage._morphology:binary_opening
Signature
def binary_opening ( input , structure = None , iterations = 1 , output = None , origin = 0 , mask = None , border_value = 0 , brute_force = False , * , axes = None ) Summary
Multidimensional binary opening with the given structuring element.
Extended Summary
The opening of an input image by a structuring element is the dilation of the erosion of the image by the structuring element.
Parameters
input: array_likeBinary array_like to be opened. Non-zero (True) elements form the subset to be opened.
structure: array_like, optionalStructuring element used for the opening. Non-zero elements are considered True. If no structuring element is provided an element is generated with a square connectivity equal to one (i.e., only nearest neighbors are connected to the center, diagonally-connected elements are not considered neighbors).
iterations: int, optionalThe erosion step of the opening, then the dilation step are each repeated
iterationstimes (one, by default). Ifiterationsis less than 1, each operation is repeated until the result does not change anymore. Only an integer of iterations is accepted.output: ndarray, optionalArray of the same shape as input, into which the output is placed. By default, a new array is created.
origin: int or tuple of ints, optionalPlacement of the filter, by default 0.
mask: array_like, optionalIf a mask is given, only those elements with a True value at the corresponding mask element are modified at each iteration.
border_value: int (cast to 0 or 1), optionalValue at the border in the output array.
brute_force: boolean, optionalMemory condition: if False, only the pixels whose value was changed in the last iteration are tracked as candidates to be updated in the current iteration; if true all pixels are considered as candidates for update, regardless of what happened in the previous iteration. False by default.
axes: tuple of int or NoneThe axes over which to apply the filter. If None,
inputis filtered along all axes. If anorigintuple is provided, its length must match the number of axes.
Returns
binary_opening: ndarray of boolsOpening of the input by the structuring element.
Notes
Opening [1] is a mathematical morphology operation [2] that consists in the succession of an erosion and a dilation of the input with the same structuring element. Opening, therefore, removes objects smaller than the structuring element.
Together with closing (binary_closing), opening can be used for noise removal.
Array API Standard Support
binary_opening has experimental support for Python Array API Standard compatible backends in addition to NumPy. Please consider testing these features by setting an environment variable SCIPY_ARRAY_API=1 and providing CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following combinations of backend and device (or other capability) are supported.
==================== ==================== ==================== Library CPU GPU ==================== ==================== ==================== NumPy ✅ n/a CuPy n/a ✅ PyTorch ✅ ⛔ JAX ⚠️ no JIT ⛔ Dask ⚠️ computes graph n/a ==================== ==================== ====================
See
dev-arrayapifor more information.
Examples
from scipy import ndimage import numpy as np a = np.zeros((5,5), dtype=int) a[1:4, 1:4] = 1; a[4, 4] = 1 a ndimage.binary_opening(a, structure=np.ones((3,3))).astype(int) ndimage.binary_opening(a).astype(int) ndimage.binary_erosion(a).astype(int) ndimage.binary_dilation(ndimage.binary_erosion(a)).astype(int)✓
See also
Aliases
-
scipy.ndimage.binary_opening