imerode
-
說明:侵蝕操作:使用指定的結構元素侵蝕源圖像,該結構元素確定了取最小值的像素鄰域的形狀。對於多通道圖像,每個通道都將獨立處理。
-
參數
- img (
np.ndarray):輸入圖像。 - ksize (
Union[int, Tuple[int, int]]):結構元素的大小。預設為 (3, 3)。 - kstruct (
str | int | MORPH):元素形狀。可用MORPH.CROSS/RECT/ELLIPSE、字串"CROSS"/"RECT"/"ELLIPSE"或 OpenCV 的整數值。預設為MORPH.RECT。
- img (
-
範例
import numpy as np
from capybara.vision.morphology import imerode
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)
eroded_img = imerode(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 erosion, the image will be like this:
# >>> np.array([[0, 0, 0, 0, 0],
# [0, 0, 0, 0, 0],
# [0, 0, 1, 0, 0],
# [0, 0, 0, 0, 0],
# [0, 0, 0, 0, 0]], dtype=np.uint8)