Shifting a fourier spectrum by subpixel amount in python I am working on a Fourier Ptychography problem. My research problem requires me to shift the Fourier spectrum of an image by a floating-point value. For a real-valued image, we can simply use cv2.warpAffine to shift the image by floating-point values (aka subpixel shifting).

Taking fourier transform of an image produces a complex matrix. The problem is, cv2.warpAffine does not support complex matrices, and so I cannot use it on them. I tried searching for alternatives, but none of them seem to work. I came across numpy.roll, but the problem is, it does not support subpixel shifting. Rounding off the shifting values translates to loss of information in my case. Is there a solution in python, that allows for subpixel shifting on complex matrices?

Thanks.

EDIT: Based on Marcus' answer, I did some digging and implemented a nifty little script for subpixel shifting in python based on a Matlab script for the same.

Here's the link to the script. Hope it helps!
You'd not do it in frequency domain at all. Use the shift property of the discrete Fourier transform!

Simply multiply the rows of your original image with an $e^{j2\pi \Delta f_x x/W}$ pointwise ($x$: pixel index in that row, $W$: width of image) before transforming to frequency domain to shift by $\Delta f_x$ in row direction. Same for shifts in column direction; multiply columns with $e^{j2\pi \Delta f_y y/H}$ pointwise ($y$: pixel index in that column, $H$: height of image). There's no restrictions on the "fineness" of $\Delta f$ in either direction, and any 2D shift can be understood as a shift in row and one in column direction.

If necessary, transform your image from frequency to spatial domain, do the multiplications, and transform back.