If you are using torch.rfft
, then you can set onesided=False
to get the full transform back.
That documentation doesn't say anything about how the output is formatted, the best guess is to assume it returns the first half of the elements along the last dimension, meaning that ft[i,j]
, with i
in half-open range [0
,in.shape[0]
), j
in half-open range [0
,in.shape[1]
), and in
the input image, can be read as follows:
cutoff = in.shape[1] // 2 + 1
if j >= cutoff:
return ft[-i, in.shape[1] - j].conj()
else:
return ft[i, j]
If you use skcuda.fft.fft
, the documentation is equally explicit, and therefore I'd make the same guess as above.
To obtain a full DFT out of the half-plane DFT returned by these functions, use the following code:
import numpy as np
size = 6
halfsize = size // 2 + 1
half_ft = np.random.randn(size, halfsize) # example half-plane DFT
if size % 2:
# odd size input
other_half = half_ft[:, -1:0:-1]
else:
# even size input
other_half = half_ft[:, -2:0:-1]
other_half = np.conj(other_half[np.hstack((0, np.arange(size-1, 0, -1))), :])
full_ft = np.hstack((half_ft, other_half))
That is, we flip the array along both dimensions (this is the 2D case, adjust as needed for other dimensionalities), but the first row and column (DC components) are not repeated, and for even-sized input, the last row and column are not repeated either.