i必须使用肌形滤波来处理numpy框架,才能获得Fisherfaces的图像,从而改善了识别率。我需要使用Python语言的同等同态过滤。我尝试在opencv(v2.4)中搜索一些函数,而没有找到解决方案。 我还看到了这一点(以及许多其他链接): cplusplus语言中的HOMormormormormthic滤波。 但这还没有解决我的问题。 我希望你能帮助我。 谢谢你很多。
用解释了here
γH> 1和γ
以下代码在日志域中的图像上应用上述过滤器,并与输入图像一起显示过滤后的输出。 import numpy as np from skimage.io import imread def homomorphic_filter(f, D0, γ_l, γ_h, c): h, w = f.shape u, v = np.meshgrid(range(-w//2,w//2), range(-h//2,h//2)) # assuming h, w even D = np.sqrt(u**2 + v**2) H = 1 - np.exp(-c*D**2/(D0**2)) # gaussian high-pass H = ((γ_h - γ_l)*H) + γ_l H = 1 - H F = np.fft.fft2(np.log2(1+f)) G = H * F # by convolution theorem g = np.exp(np.abs(np.fft.ifft2(G))) return g D0, n = 10, 2 im = imread('tunnel.png', as_gray=True) im = (255*im/im.max()).astype(np.float32) # pixel values scaled in between [0-255] # np.seterr(divide='ignore') im_out = homomorphic_filter(im, D0, γ_l = .0999, γ_h = 1.01, c = 0.5)
import numpy as np from skimage.io import imread def homomorphic_filter(f, D0, γ_l, γ_h, c): h, w = f.shape u, v = np.meshgrid(range(-w//2,w//2), range(-h//2,h//2)) # assuming h, w even D = np.sqrt(u**2 + v**2) H = 1 - np.exp(-c*D**2/(D0**2)) # gaussian high-pass H = ((γ_h - γ_l)*H) + γ_l H = 1 - H F = np.fft.fft2(np.log2(1+f)) G = H * F # by convolution theorem g = np.exp(np.abs(np.fft.ifft2(G))) return g D0, n = 10, 2 im = imread('tunnel.png', as_gray=True) im = (255*im/im.max()).astype(np.float32) # pixel values scaled in between [0-255] # np.seterr(divide='ignore') im_out = homomorphic_filter(im, D0, γ_l = .0999, γ_h = 1.01, c = 0.5)
<1, the constant c controls smoothness.