理想高通滤波实现Python opencv示例
程序员文章站
2022-07-22 11:25:08
理想高通滤波实现 python opencv
import numpy as np
import cv2
from matplotlib import p...
理想高通滤波实现 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) h1 = np.zeros((m,n)) h2 = np.zeros((m,n)) h3 = 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: h1[i,j]=1 else: h1[i,j]=0 if d>=d2: h2[i,j]=1 else: h2[i,j]=0 if d>=d3: h3[i,j]=1 else: h3[i,j]=0 guv1 = h1*fuv guv2 = h2*fuv guv3 = h3*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()
效果:
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对的支持。如果你想了解更多相关内容请查看下面相关链接
上一篇: 如何在linux网卡上添加多个IP
下一篇: fstab 格式