簡單來說,膨脹就是把圖像中的物體變大了!
與腐蝕操作一樣,A matrix parameter is also required.
膨脹函數:dilate(圖像,矩陣)
示例圖片:
源碼
import cv2
import numpy as np
csdn_img = cv2.imread("./csdn2.jpg") # 讀取圖像
k1 = np.ones((3, 3), np.uint8) # 3expansion units of different scales
k2 = np.ones((5, 5), np.uint8)
k3 = np.ones((9, 9), np.uint8)
k1_img = cv2.dilate(csdn_img, k1) # 膨脹函數
k2_img = cv2.dilate(csdn_img, k2)
k3_img = cv2.dilate(csdn_img, k3)
cv2.imshow("csdn_img", csdn_img)
cv2.imshow("k1_img", k1_img)
cv2.imshow("k2_img", k2_img)
cv2.imshow("k3_img", k3_img)
cv2.waitKey(0)
執行結果:
The collision matrix is:(3, 3)
The collision matrix is:(5,5)
The collision matrix is:(9,9)