正在努力执行任务 here 在python中。我需要对灰度图像进行加波滤波,然后对加波滤波后的图像进行高斯滤波。在观察Python代码和MATLAB代码的结果时,我发现它们是完全不同的。
在python中,有cv2.filter2D cv2.GaussianBlur等函数用于Garbor和Gaussian滤波,正如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)