正在尝试在python中实现任务here。我需要对灰度图像执行Garbor滤波,然后对garbor滤波图像执行高斯滤波。在观察Python代码和MATLAB代码的结果时,我发现它们完全不同。
在python中,有函数cv2.filter2D cv2.GaussianBlur用于Garbor和高斯滤波,就像MATLAB具有imgaborfilt和imgaussfilt一样。如代码片段所示,使用python函数将返回仅0和1的矩阵,而MATLAB将返回浮点数的矩阵。
def garbor_filters(wavelength, orientation):
ksize = 39
kern = cv2.getGaborKernel(ksize=(ksize, ksize), sigma = 0.5, theta=orientation, lambd=wavelength, gamma=math.sqrt(2), psi=0, ktype=cv2.CV_32F)
return kern
def compute_garbor(img, filter):
#filter: kernel obtained from the method above
filtered_img = cv2.filter2D(img, cv2.CV_8UC3, filter)
return filtered_img
def getgaussianFiltrdImg(imageGarbors, filters):
#filters: a tuple of wavelength and orientation
sigma = 0.5*filters[0]; #get wavelength
K = 3;
filtersize=2*math.ceil(2*K*sigma)+1
gau_img = cv2.GaussianBlur(imageGarbors, (filtersize,filtersize), K*sigma)
return gau_img
# call the methods
realimage = cv2.imread('kobi.png')
realimage = cv2.cvtColor(realimage, cv2.COLOR_BGR2GRAY)
img = rescale(realimage, 0.25, anti_aliasing=False)
imageGarbors=getImageGabor(img, (2.82,0))
imageGauss=getgaussianFiltrdImg(imageGarbors, (2.82,0))
Python在矩阵中仅返回0和1,而MATLAB返回连续值。我在做什么错了?