## cv2.erode() ### 用途 1. Erosion 影像侵蝕對於移除影像中的小白雜點很有幫助,可用來去噪,例如影像中的小雜點,雜訊。 2. 細化影像,消除毛刺。 ### Define ```python cv.erode(src, kernel[, dst[, anchor[, iterations[, borderType[, borderValue]]]]]) ->dst ``` ### Arguments `src`: 二值化的影像 `kernel`: 捲積 kernel `iterations`: 迭代次數(預設為1) ## cv2.dilate() ### 用途 1. Dilation 影像膨脹通常是配合著影像侵蝕 Erosion 使用,先使用侵蝕的方式使影像中的線條變窄,同時也去除雜訊,之後再透過 Dilation 將影像膨脹回來。 2. 用來連接兩個很靠近但分開的物體。 ### Define ```python cv.dilate(src, kernel[, dst[, anchor[, iterations[, borderType[, borderValue]]]]]) ->dst ``` ### Arguments `src`: 二值化的影像 `kernel`: 捲積 kernel `iterations`: 迭代次數(預設為1) ## cv2.GaussianBlur() 高斯濾波與平均濾波 Averaging 類似,平均濾波 Averaging 的 kernel 裡的每個 pixel 權重都是1,而高斯濾波給予每個 pixel 不同權重,中心 pixel 的權重最高,越往邊角權重就越低,相較於平均濾波 Averaging 這樣可以讓圖片失真較少,高斯濾波通常去除雜訊也有不錯的效果。 ## cv2.canny() ```python cv.Canny( image, threshold1, threshold2[, edges[, apertureSize[, L2gradient]]] ) -> edges ``` Canny函数的使用很简单,指定最大(`threshold2`)和最小 threshold(`threshold1`),其中 `apertureSize` 預設為3。