我正在尝试使用 OpenCV 包将一段 Matlab 代码转换为 python。但我不知道如何在 Matlab 中实现 filter2。这是matlab代码。
imdist = imread("testimage1.bmp");
imdist = rgb2gray(imdist);
window = fspecial('gaussian',7,7/6);
window = window/sum(sum(window));
mu = filter2(window, imdist, 'same');
我的python代码在这里:
import pyopencv as cv
import numpy as np
img = cv.imread("testimage1.bmp")
imdist = cv.Mat()
cv.cvtColor(img, imdist, cv.CV_BGR2GRAY)
row = cv.getGaussianKernel(7, 7.0/6.0)
col = cv.getGaussianKernel(7, 7.0/6.0)
window = cv.asMat(np.dot(col[:], row[:].T))
window = cv.asMat(window[:]/sum(sum(window[:])))
mu = cv.Mat()
# I'm not sure it should be filter2D
cv.filter2D(imdist, mu, -1, window)
过滤器掩码“窗口”是相同的。但是变量“mu”与matlab结果不同。请帮我。