title: How to correctly replace the real part of the FFT?
body: <p>I try to reproduce a data augmentation method, which comes from the paper:</p>
  <p><em>Qinwei Xu, Ruipeng Zhang, Ya Zhang, Yanfeng Wang and Qi Tian</em> <a href="https://openaccess.thecvf.com/content/CVPR2021/papers/Xu_A_Fourier-Based_Framework_for_Domain_Generalization_CVPR_2021_paper.pdf" rel="nofollow noreferrer"><strong>&quot;A Fourier-based Framework for Domain Generalization&quot;</strong></a> (CVPR 2021).</p>
  <p>It is mentioned in the paper that they set the real part to a constant (the constant in the paper is 20000) to eliminate the amplitude and realize the reconstruction of the image relying only on the phase.
  Below is my code:</p>
  <pre><code>img = process_img(&quot;./data/house.jpg&quot;, 128)
  img_fft = torch.fft.fft2(img, dim=(-2, -1))
  amp = torch.full(img_fft.shape, 200000)
  img_fft.real = amp
  img_ifft = torch.fft.ifft2(img_fft, dim=(-2, -1))
  
  img_ifft = img_ifft.squeeze(0)
  img_ifft = img_ifft.transpose(2, 0)
  
  img_ifft = np.array(img_ifft)
  
  cv2.imshow(&quot;&quot;, img_ifft.real)
  </code></pre>
  <p>Among them, the process_img function is only used to convert ndarray to tensor, as shown below:</p>
  <pre><code>loader = transforms.Compose([transforms.ToTensor()])
  def process_img(img_path, img_size):
      img = cv2.imread(img_path)
      img = cv2.resize(img, (img_size, img_size))
      img = img.astype(np.float32) / 255.0
      img = loader(img)
      img = img.unsqueeze(0)
      return img
  </code></pre>
  <p>The first is the original image, the second is the image provided by the paper, and the third is the image generated by my code:</p>
  <p><img src="https://i.stack.imgur.com/tl8pP.png" alt="Image comparison" /></p>
  <p>It can be seen that the images generated by my method are very different from those provided in the paper, and there are some artifacts. Why is there such a result?</p>