Hi, thank you always for your support.
I am trying to Fourier transform an image using the torch.rfft, but I cannot guess how I can get a frequency map and retrieve the original image by ifft.
The output frequency map has actually the column size half of the original map and 2 elements are real and imaginary number I suppose. How can I visualize the frequency map and calculate the energy of the image?
Thank you in advance:)
The code is as follows:
from PIL import Image
import torchvision.transforms.functional as TF
…
file_path = “test_image.jpg”
image = TF.to_tensor(Image.open(file_path)).unsqueeze_(0)
# The size of “image_ch” is torch.Size([128, 128])
image_ch = torch.squeeze(image[:,0:1,:,:], 0)
spatial_map = torch.squeeze(image_ch, 0)
# The size of “fft_map” is torch.Size([128, 64, 2])
fft_map = torch.rfft(spatial_map, signal_ndim=2)
# The size of “spatial_map_retrieved” is torch.Size([128, 64, 2])
spatial_map_retrieved = torch.ifft(fft_map, signal_ndim=2)