psychopy.org | Reference | Downloads | Github

Maybe a problem in the definition of imifft (inverse fourier transform)?


#1

Doing the inverse fourier transform with visual.filters.imifft of the fourier tranform with visual.filters.imfft does not recover the original image. This does not happen using directly the fourier transform functions from numpy

import numpy as np
from psychopy import visual, event

x=visual.filters.makeGrating(128, cycles = 4)
xDisplay= x*2.0-1.0

xPsychopy=visual.filters.imifft(visual.filters.imfft(x))
xPsychopyDisplay=xPsychopy*2.0-1.0

xNumpy=np.fft.ifft2(np.fft.ifftshift(np.fft.fftshift(np.fft.fft2(x))))
xNumpyDisplay=xNumpy*2.0-1.0

win = visual.Window([600,600], monitor='testMonitor', units='pix')
original = visual.ImageStim(win, image = xDisplay, mask=None, size=128,pos=[-100,100])
psycho = visual.ImageStim(win, image = xPsychopyDisplay, mask=None, size=128,pos=[-100,-100])
nump = visual.ImageStim(win, image = xNumpyDisplay, mask=None, size=128,pos=[100,-100])

original.draw()
psycho.draw()
nump.draw()

win.flip()
event.waitKeys()

#2

Hi Dani,

It looks like imifft runs abs before returning, whereas your numpy version in the above has an (implicit) real (ComplexWarning: Casting complex values to real discards the imaginary part). I think that real would be more typical usage?