imdilate
-
Description: Dilation operation: Dilates the source image using a specified structuring element, which determines the shape of the pixel neighborhood from which the maximum value is taken. For multi-channel images, each channel will be processed independently.
-
Parameters
- img (
np.ndarray
): Input image. - ksize (
Union[int, Tuple[int, int]]
): Size of the structuring element. Default is (3, 3). - kstruct (
MORPH
): Shape of the element, which can be one of "MORPH.CROSS", "MORPH.RECT", or "MORPH.ELLIPSE". Default is "MORPH.RECT".
- img (
-
Example
import numpy as np
import docsaidkit as D
img = np.array([[0, 0, 0, 0, 0],
[0, 1, 1, 1, 0],
[0, 1, 1, 1, 0],
[0, 1, 1, 1, 0],
[0, 0, 0, 0, 0]], dtype=np.uint8)
dilated_img = D.imdilate(img, ksize=3, kstruct='RECT')
# Kernel will be like this:
# >>> np.array([[1, 1, 1],
# [1, 1, 1],
# [1, 1, 1]], dtype=np.uint8)
# After dilation, the image will be like this:
# >>> np.array([[1, 1, 1, 1, 1],
# [1, 1, 1, 1, 1],
# [1, 1, 1, 1, 1],
# [1, 1, 1, 1, 1],
# [1, 1, 1, 1, 1]], dtype=np.uint8)