title: FFT on image with Python
body: <p>I have a problem with FFT implementation in Python. I have completely strange results. 
  Ok so, I want to open image, get value of every pixel in RGB, then I need to use fft on it, and convert to image again.</p>
  
  <p>My steps:</p>
  
  <p>1) I'm opening image with PIL library in Python like this</p>
  
  <pre><code>from PIL import Image
  im = Image.open("test.png")
  </code></pre>
  
  <p>2) I'm getting pixels</p>
  
  <pre><code>pixels = list(im.getdata())
  </code></pre>
  
  <p>3) I'm seperate every pixel to r,g,b values</p>
  
  <pre><code>for x in range(width):
      for y in range(height):
          r,g,b = pixels[x*width+y]
          red[x][y] = r
          green[x][y] = g
          blue[x][y] = b
  </code></pre>
  
  <p>4). Let's assume that I have one pixel (111,111,111). And use fft on all red values like this</p>
  
  <pre><code>red = np.fft.fft(red)
  </code></pre>
  
  <p>And then:</p>
  
  <pre><code>print (red[0][0], green[0][0], blue[0][0])
  </code></pre>
  
  <p>My output is:</p>
  
  <pre><code>(53866+0j) 111 111
  </code></pre>
  
  <p>It's completely wrong I think. My image is 64x64, and FFT from gimp is completely different. Actually, my FFT give me only arrays with huge values, thats why my output image is black.</p>
  
  <p>Do you have any idea where is problem?</p>
  
  <p>[EDIT]</p>
  
  <p>I've changed as suggested to</p>
  
  <pre><code>red= np.fft.fft2(red)
  </code></pre>
  
  <p>And after that I scale it</p>
  
  <pre><code>scale = 1/(width*height)
  red= abs(red* scale)
  </code></pre>
  
  <p>And still, I'm getting only black image.</p>
  
  <p>[EDIT2]</p>
  
  <p>Ok, so lets take one image. <a href="https://i.stack.imgur.com/H6Gp7.png" rel="noreferrer"><img src="https://i.stack.imgur.com/H6Gp7.png" alt="test.png"></a></p>
  
  <p>Assume that I dont want to open it and save as greyscale image. So I'm doing like this.</p>
  
  <pre><code>def getGray(pixel):
      r,g,b = pixel
      return (r+g+b)/3  
  
  im = Image.open("test.png")
  im.load()
  
  pixels = list(im.getdata())
  width, height = im.size
  for x in range(width):
      for y in range(height):
          greyscale[x][y] = getGray(pixels[x*width+y])  
  
  data = []
  for x in range(width):
       for y in range(height):
           pix = greyscale[x][y]
           data.append(pix)
  
  img = Image.new("L", (width,height), "white")
  img.putdata(data)
  img.save('out.png')
  </code></pre>
  
  <p>After this, I'm getting this image <a href="https://i.stack.imgur.com/t8LqJ.png" rel="noreferrer"><img src="https://i.stack.imgur.com/t8LqJ.png" alt="greyscale"></a>, which is ok. So now, I want to make fft on my image before I'll save it to new one, so I'm doing like this</p>
  
  <pre><code>scale = 1/(width*height)
  greyscale = np.fft.fft2(greyscale)
  greyscale = abs(greyscale * scale)
  </code></pre>
  
  <p>after loading it. After saving it to file, I have <a href="https://i.stack.imgur.com/ZmHSR.png" rel="noreferrer"><img src="https://i.stack.imgur.com/ZmHSR.png" alt="bad FFT"></a>. So lets try now open test.png with gimp and use FFT filter plugin. I'm getting this image, which is correct <a href="https://i.stack.imgur.com/etJgL.png" rel="noreferrer"><img src="https://i.stack.imgur.com/etJgL.png" alt="good FFT"></a></p>
  
  <p>How I can handle it?</p>