小编给大家分享一下高通滤波怎么实现Python opencv示例,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!
理想高通滤波实现 python opencv
import numpy as np import cv2 from matplotlib import pyplot as plt plt.rcParams[‘font.sans-serif']=[‘SimHei'] plt.rcParams[‘axes.unicode_minus'] = False I = cv2.imread(‘capture3.png') cv2.imshow(‘original',I) (r,g,b) = cv2.split(I) I = cv2.merge([b,g,r]) J = np.double(cv2.cvtColor(I,cv2.COLOR_RGB2GRAY)) D1 = 30 D2 = 60 D3 = 160 Fuv = np.fft.fftshift(np.fft.fft2(J)) print(‘Fuv',Fuv) print(I.shape) m,n = I.shape[0],I.shape[1] xo = np.floor(m/2) yo = np.floor(n/2) h2 = np.zeros((m,n)) h3 = np.zeros((m,n)) h4 = np.zeros((m,n)) for i in range(m): for j in range(n): D = np.sqrt((i-xo)**2+(j-yo)**2) if D>=D1: h2[i,j]=1 else: h2[i,j]=0 if D>=D2: h3[i,j]=1 else: h3[i,j]=0 if D>=D3: h4[i,j]=1 else: h4[i,j]=0 Guv1 = h2*Fuv Guv2 = h3*Fuv Guv3 = h4*Fuv g1 = np.fft.ifftshift(Guv1) g1 = np.uint8(np.real(np.fft.ifft2(g1))) print(‘g1',g1) g2 = np.fft.ifftshift(Guv2) g2 = np.uint8(np.real(np.fft.ifft2(g2))) print(‘g2',g2) g3 = np.fft.ifftshift(Guv3) g3 = np.uint8(np.real(np.fft.ifft2(g3))) print(‘g3',g3) plt.subplot(2,2,1),plt.imshow(I),plt.title(‘原图像') plt.subplot(2,2,2),plt.imshow(g1),plt.title(‘D0=30') plt.subplot(2,2,3),plt.imshow(g2),plt.title(‘D0=60') plt.subplot(2,2,4),plt.imshow(g3),plt.title(‘D0=160') plt.show()
效果:
看完了这篇文章,相信你对“高通滤波怎么实现Python opencv示例”有了一定的了解,如果想了解更多相关知识,欢迎关注亿速云行业资讯频道,感谢各位的阅读!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。