为了研究cv2.GaussianBlur()内部的计算逻辑 可以分为两部分,第一步获取高斯核, 第二步滑动窗口进行卷积操作. ta = cv2.GaussianBlur(da, (kernel, kernel), 0)
(1)设高斯kernel=3,sigma=0, 可得高斯核为: ka = gaussian_kernel_2d(kernel, 0) (2)使用高斯核进行卷积, 为了方便, 这里不考虑位于矩阵边界的值, 可得高斯模糊的结果: radium = kernel//2 rows, cols = db.shape result2 = copy.deepcopy(db) for i in range(radium, rows-radium, 1): for j in range(radium, rows-radium, 1): result2[i, j] = (db[i-radium:i+radium+1, j-radium:j+radium+1] * ka).sum()
(3)与直接使用cv2.GaussianBlur的计算结果保持一致.
另外,经计算发现,borderType=cv2.BORDER_CONSTANT时, 边界填充值为0.
参考资料: https://blog.csdn.net/weixin_37804469/article/details/113843829?spm=1001.2101.3001.6650.8&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-8-113843829-null-114199025.pc_relevant_downloadblacklistv1&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-8-113843829-null-114199025.pc_relevant_downloadblacklistv1&utm_relevant_index=12 https://blog.csdn.net/weixin_41563746/article/details/114199025 https://cloud.tencent.com/developer/article/1165877 https://docs.opencv.org/2.4/modules/imgproc/doc/filtering.html?highlight=gaussianblur#int%20borderInterpolate(int%20p,%20int%20len,%20int%20borderType)
https://docs.opencv.org/3.4/dc/da3/tutorial_copyMakeBorder.html
|