离散傅立叶变换:低通滤波器不会削减适当的频率

时间:2017-10-04 15:17:07

标签: python opencv numpy python-3.5

我使用以下步骤在cv2.dft()中使用python 3.5

余弦图像为:enter image description here

N=32
Icos = np.zeros((32,32))
for i in range(0,N):
    for j in range(0,N):
        myPi = 2*math.pi/N
        th1 = 8*i + 6*j
        th2 = 4*i + 2*j
        th3 = 2*j
        Icos[i,j] = (0.25 * math.cos(myPi*th1) + 0.75*math.cos(myPi*th2) + math.cos(myPi*th3))
image = Icos

dft = cv2.dft(np.float32(image),flags =cv2.DFT_COMPLEX_OUTPUT)

#Shift to the center
dft_shift = np.fft.fftshift(dft)

#Magnitude Calculation
ms = np.log(1+cv2.magnitude(dft_shift[:,:,0],dft_shift[:,:,1]))

mask_out = 'Mask LowPass'
mask = np.zeros((rows,cols,2),np.uint8)


for i in range(0,rows):
    for j in range(0,cols):
        point = math.sqrt(math.pow((i-crow),2)+math.pow((j-ccol),2))
        if point <= radius1:
            mask[i,j]=1
#apply mask
fshift = dft_shift*mask

#Inverse
f_ishift = np.fft.ifftshift(fshift)
img_back = cv2.idft(f_ishift)
img_back = cv2.magnitude(img_back[:,:,0],img_back[:,:,1])

#Fourier Transform of the resulted image
dft_res = cv2.dft(np.float32(img_back),flags =cv2.DFT_COMPLEX_OUTPUT)

#Shift to the center
dft_shift_res = np.fft.fftshift(dft_res)

#Magnitude Calculation
ms_res = np.log(1+cv2.magnitude(dft_shift_res[:,:,0],dft_shift_res[:,:,1]))

如下所示,当我使用radius1 = 7时,所得到的反转图像的幅度谱似乎不正确。

enter image description here

反转图像的幅度谱(如果我再次执行dft / fftshift)不会与此类似吗?

enter image description here

反转图像看起来应该是这样吗?

enter image description here

0 个答案:

没有答案