使用 OpenCV 函式 erode() 侵蝕影像


在本程式中,我們將使用 OpenCV 函式 erode() 侵蝕影像。影像侵蝕是指縮小影像。如果核中的任何畫素為 0,則核中的所有畫素都將設為 0。在對影像應用侵蝕函式之前有一個條件,即影像應為灰度影像。

原始影像

演算法

Step 1: Import cv2
Step 2: Import numpy.
Step 3: Read the image using imread().
Step 4: Define the kernel size using numpy ones.
Step 5: Pass the image and kernel to the erode function.
Step 6: Display the output.

示例程式碼

import cv2
import numpy as np
image = cv2.imread('testimage.jpg')
kernel = np.ones((7,7), np.uint8)
image = cv2.erode(image, kernel)
cv2.imshow('Eroded Image', image)

輸出

更新於:2021 年 3 月 17 日

444 閱讀

開啟你的 職業生涯

完成課程獲得認證

開始學習
廣告