TypeError: src data type = 15 is not supported
Asked Answered
G

2

3

I want to use Fast Fourier Transform but already trying a simple back and forth transformation doesn't work. The code is

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])

and the error is

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

How can this be fixed?

Guenevere answered 22/6, 2015 at 21:12 Comment(0)
G
1

I think I figured it out. cv2.idft() wants the complex numbers in a different format. I had to extract the real and imaginary part separately and write them in the third dimension:

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])
Guenevere answered 22/6, 2015 at 21:32 Comment(0)
O
-1

Sometimes it wants an absolute value returns so you could use: np.abs()

Olivas answered 6/3, 2021 at 16:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.