0
낮은 푸리에 변환을 필터링하려고합니다. 제공된 예제를 사용하여 올바른 이미지 표현을 얻을 수 있습니다. 그러나 이미지를 다시 얻으려면 역변환을 어떻게 얻을 수 있는지 잘 모르겠습니다. dft_shift는 float32 (256,320,2)입니다. 크기 스펙트럼을 얻으려면, 로그를 계산하기 위해 cv2.magnitude (dft_shift [:, :, 0] 및 dft_shift [:, :, 1])를 추출한 예제를 사용했습니다. 왜 np.log가 두 개의 입력을 받는지 잘 모르겠습니다. ? magitude_spectrum는 float32 (256320) 그래서 난 그냥 할 (컨텍스트에 대한 코드를 넣고 참조) 할 수있다 :푸리에 변환 크기 필터링
f_ishift = np.fft.ifftshift(mag_spec)
img_back = np.fft.ifft2(f_ishift)
img_back = np.abs(img_back)
어떤 제안이 나는이 시점에서 필사적입니다 ... 여기
이 코드의과 결과 :import cv2
import numpy as np
from matplotlib import pyplot as plt
img = cv2.imread('G:\\Python\\Original\\frame13.jpg',0)
dft = cv2.dft(np.float32(img),flags = cv2.DFT_COMPLEX_OUTPUT)
dft_shift = np.fft.fftshift(dft)
magnitude_spectrum = 20*np.log(cv2.magnitude(dft_shift[:,:,0],dft_shift[:,:,1]))
rows, cols = img.shape
mag_spec=20*np.log(cv2.magnitude(dft_shift[:,:,0],dft_shift[:,:,1]))
for i in range(0,rows-1):
for j in range(0,cols-1):
if mag_spec[i,j]<130:
mag_spec[i,j]=0
f_ishift = np.fft.ifftshift(mag_spec)
img_back = np.fft.ifft2(f_ishift)
img_back = np.abs(img_back)
plt.subplot(121),plt.imshow(magnitude_spectrum, cmap = 'gray')
plt.title('Magnitude spectrum'), plt.xticks([]), plt.yticks([])
plt.subplot(122),plt.imshow(mag_spec, cmap = 'gray')
plt.title('With mask'), plt.xticks([]), plt.yticks([])
plt.show()