DFT(discrete fourier transform)show phase spectrum of a picture,why I got a Symmetric picture after IDFT

25 Views Asked by At

I use DFT to transform a Image to spectrum,and I want to show the result of inverse transform only on its phase spectrum.I saw other people have make it and can observe the the structural semantics of the picture.I use my code to implement it,but the result is strange,the picture has some symmetrical structure.

example: picture of a dog
The left is the original picture.The middle is my result.The Right is other people result.What error in my code?Maybe the symmetrical structure is difficult to observe in dog picture example.I provide anohter example which can observe a symmetrical structure. example: Asuna

the code as below:

from PIL import Image
import torch
from torchvision import transforms
import matplotlib.pyplot as plt

img = Image.open("./test.jpg")
img_tensor = transforms.ToTensor()(img)
img_fft = torch.fft.fft2(img_tensor)
img_fft_shift = torch.fft.fftshift(img_fft)

phase = torch.angle(img_fft_shift) 

img_inverse = torch.abs(torch.fft.ifft2(torch.fft.ifftshift(phase)))
img_inverse = (img_inverse - img_inverse.min()) / (img_inverse.max() - img_inverse.min())
plt.imshow(img_inverse.permute(1,2,0))

I want the result as the example: picture of a dog right one,which we can observe the Outline of the dog and we can't observe a symmetrical structure.

0

There are 0 best solutions below