title: R - FFT Fourier Spectrum of Image
body: <p>I am using R Studio in sake of doing my tasks in Image Processing. I am currently using the 'EBImage, fftw, ...' libraries. I have a question about fourier analysis and power spectrum.</p>
  
  <p>1) I have 2D matrix, which is an image. This image consist on horizontal lines, black and white. I want to make Fourier Transformation and show its magnitude by ploting. Since the black lines in image are horizontal, the power spectrum will have an vertical line. I couldn't find a way to achieve it.</p>
  
  <p>Now I am using this image for test: 
  <a href="https://i.stack.imgur.com/OYBXZ.jpg" rel="nofollow noreferrer">Square</a></p>
  
  <p>When it is true, this image has some periodic frequencies on both horizontal and vertical axis. Then. the FFT Spectrum should look like a "+". But what I found is something way different.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>setwd(".../Project/R/Workspace/Task1")
  library("EBImage"  , lib.loc="~/R/win-library/3.2")
  library("fftwtools", lib.loc="~/R/win-library/3.2")
  library("fftw", lib.loc="~/R/win-library/3.2")
  
  # Image Acquisition
  img &lt;- readImage(".../Project/Beispielbilder/drmcircle.jpg")
  display(img, title='Image')
  
  # Grayscaled
  img_gray&lt;-channel(img,"gray")
  
  # FFT
  img_ff &lt;- fft(img_gray)    #fftw2d
  
  magntd &lt;- sqrt(Re(img_ff)^2+Im(img_ff)^2)
  phase  &lt;- atan(Im(img_ff)/Re(img_ff))
  
  plot(log(magntd),main="FFT")
  </code></pre>
  
  <p>As a result, this is what I have:
  <a href="https://i.stack.imgur.com/TV1ls.jpg" rel="nofollow noreferrer">FFT Spectrum</a></p>
  
  <p>Here are my questoions:</p>
  
  <p>1) How can I get a correct spectrum image?
  2) How can I see it as an image, not a plot? (See Example Link on top.)</p>
  
  <p>Thank you for your help in advance.</p>