TypeError: src data type = 15 is not supported

TypeError: src data type = 15 is not supported

我想使用快速傅立叶变换,但已经尝试过简单的来回变换,但行不通。密码是

import cv2
import numpy as np

img = cv2.imread('Picture.bmp',0)
f = np.fft.fft2(img)
fshift = np.fft.fftshift(f)
f_ishift = np.fft.ifftshift(fshift)
img_back = cv2.idft(f_ishift)
img_back = cv2.magnitude(img_back[:,:,0],img_back[:,:,1])

错误是

Traceback (most recent call last):
  File "test.py", line 8, in <module>
    img_back = cv2.idft(f_ishift)
TypeError: src data type = 15 is not supported

如何解决这个问题?

我想我明白了。 cv2.idft() 想要不同格式的复数。只好把实部和虚部分别提取出来写在三维中:

import cv2
import numpy as np

img = cv2.imread('Bild.bmp',0)
f = np.fft.fft2(img)
fshift = np.fft.fftshift(f)
f_ishift = np.fft.ifftshift(fshift)
d_shift = np.array(np.dstack([f_ishift.real,f_ishift.imag]))
img_back = cv2.idft(d_shift)
img = cv2.magnitude(img_back[:,:,0],img_back[:,:,1])

有时它需要一个绝对值 returns 所以你可以使用:np.abs()