Structural Mathematical Morphology
Structuring element
- pylena.morpho.make_structuring_element_2d(kind, *args)
Compute a predifined structuring element. The morphological operations for these structuring elements have been optimized for their use.
Three kinds of structuring element can be computed using this method:
2-D rectangle
Disc
2-D periodic line
For these structuring elements, argument taken by the function are different.
2-D rectangle
The supplementary arguments are the width and the height
>>> se = make_structuring_element_2d("rect", width, height)
Disc
The supplementary argument is the radius of the disc
>>> se = make_structuring_element_2d("disc", radius)
2-D periodic line
The supplementary argument are the period (represented by a tuple of int of size 2 corresponding to a point) and the half number of pixel in the line
>>> se = make_structuring_element_2d("periodic_line", (2, 5), 10)
- Parameters:
kind – The structuring element to be computed.
args – The parameters for the computation of a structuring element
- Returns:
A structuring element
- Return type:
structuring_element_2d
- Raises:
ValueError – If the kind argument is incorrect or if the argument for the structuring element computation is incorrect.
Example
The following code sample show how to compute a rectangle structuring element
>>> se = make_structuring_element_2d("rect", 10, 5) # width=10 and height=5
- pylena.morpho.erosion(img: ndarray, se: ndarray | structuring_element_2d, padding_value: int = None)
Performs an erosion by a structuring element.
Given a structuring element \(B\), the erosion \(\varepsilon(f)\) of the input image \(f\) is defined as
\[\varepsilon(f)(x) = \bigwedge \{f(y), y \in B_x\}\]- Parameters:
img (2-D array (dtype=uint8)) – The image to be processed
se (structuring_element_2d or 2-D array) – The structuring element
- Returns:
The resulting image
- Return type:
2-D array
Example
>>> img = ... # Get an image >>> from pylena.morpho import make_structuring_element_2d, erosion >>> se = make_structring_element_2d("rect", 10, 10) >>> out = erosion(img, se)
- pylena.morpho.dilation(img: ndarray, se: ndarray | structuring_element_2d, padding_value: int = None)
Performs an dilation by a structuring element.
Given a structuring element \(B\), the dilation \(\delta(f)\) of the input image \(f\) is defined as
\[\delta(f)(x) = \bigvee \{f(y), y \in B_x\}\]- Parameters:
img (2-D array (dtype=uint8)) – The image to be processed
se (structuring_element_2d or 2-D array) – The structuring element
- Returns:
The resulting image
- Return type:
2-D array
Example
>>> img = ... # Get an image >>> from pylena.morpho import make_structuring_element_2d, dilation >>> se = make_structring_element_2d("rect", 10, 10) >>> out = dilation(img, se)
- pylena.morpho.opening(img: ndarray, se: ndarray | structuring_element_2d, padding_value: int = None)
Performs an opening by a structuring element.
Given a structuring element \(B\), the dilation \(\gamma(f)\) of the input image \(f\) is defined as
\[\gamma(f) = \delta_{B}(\varepsilon_{B}(f))\]- Parameters:
img (2-D array (dtype=uint8)) – The image to be processed
se (structuring_element_2d or 2-D array) – The structuring element
- Returns:
The resulting image
- Return type:
2-D array
Example
>>> img = ... # Get an image >>> from pylena.morpho import make_structuring_element_2d, opening >>> se = make_structring_element_2d("rect", 10, 10) >>> out = opening(img, se)
- pylena.morpho.closing(img: ndarray, se: ndarray | structuring_element_2d, padding_value: int = None)
Performs an closing by a structuring element.
Given a structuring element \(B\), the dilation \(\gamma(f)\) of the input image \(f\) is defined as
\[\gamma(f) = \varepsilon_{B}(\delta_{B}(f))\]- Parameters:
img (2-D array (dtype=uint8)) – The image to be processed
se (structuring_element_2d or 2-D array) – The structuring element
- Returns:
The resulting image
- Return type:
2-D array
Example
>>> img = ... # Get an image >>> from pylena.morpho import make_structuring_element_2d, closing >>> se = make_structring_element_2d("rect", 10, 10) >>> out = closing(img, se)
- pylena.morpho.gradient(img: ndarray, se: ndarray | structuring_element_2d, padding_value: int = None)
Performs a morphological gradient, also called Beucher gradient.
Given a structuring element \(B\) and an image \(f\), the morphological gradient is defined as
\[\rho_B = \delta_B - \varepsilon_B\]- Parameters:
img (2-D array (dtype=uint8)) – The image to be processed
se (structuring_element_2d or 2-D array) – The structuring element
- Returns:
The resulting image
- Return type:
2-D array
Example
>>> img = ... # Get an image >>> from pylena.morpho import make_structuring_element_2d, gradient >>> se = make_structring_element_2d("rect", 10, 10) >>> out = gradient(img, se)