1

How does one draw the frequency domain representation of an image? I've seen in DIP books that frequency domain equivalent images are displayed, but how is that done, knowing that the result is complex? In other words, an image consists of values between 0 to 255 in spatial domain, but the result is complex in the frequency domain, so what are we really drawing?

I am currently using Javascript, but I really just want to understand the theory behind the frequency domain and filtering, and not necessarily need the code written down :)

Thomas
  • 61
  • 4
  • 1
    Welcome to Stack Overflow! This is a pretty broad question, have you tried anything or found some useful resources on the internet that you can reference in your question? – Kevin Brown-Silva Feb 08 '15 at 22:56
  • Thanks for the reply! yes I did! here's an example of a library https://github.com/wellflat/javascript-labs/tree/master/cv/fft but I'm really more interested in the theory of what is actually drawn as the frequency domain representation – Thomas Feb 08 '15 at 23:04
  • 1
    "what are they really drawing?": They're almost always drawing the magnitude of the 2D FFT (either `Re^2 + Im^2` or the `sqrt` of that). – tom10 Feb 09 '15 at 03:54
  • @tom10 oh that makes much more sense. Thanks! – Thomas Feb 09 '15 at 06:34
  • look here http://stackoverflow.com/a/26734979/2521214 the image from your link is shifted by half of size towards the middle wrapped around boundaries to get the lowest frequencies to middle position instead of corners (just for better visual perception) – Spektre Feb 09 '15 at 08:39
  • @Spektre that's actually exactly what I was looking for. Thanks all for putting me in the right direction! – Thomas Feb 09 '15 at 09:59
  • They mostly draw the magnitude of the 2D FFT or sometimes draw 2 graphs - one for the magnitude and one for the phase of the image.You need both magnitude and phase if you intend on getting the image back through a 2D IFFT operation. – KillaKem Feb 09 '15 at 11:08
  • @Thomas have edited the answer in that link of mine (from last comment here) added the power and wrap result ... – Spektre Feb 09 '15 at 12:04
  • @Spektre thanks for the effort! I actually have one more question: since my spatial domain is represented as a 1D array in JavaScript, would it be ok to just use the FFT of 1 variable as opposed to the FFT of 2? – Thomas Feb 09 '15 at 17:15
  • @Thomas you mean 1D and 2D not 1 and 2 variable I assume... You can do 2D FFT(or any other similar transform) by 1D FFT by doing all lines (as 1D transform) first then transpose then doing lines again and transpose.(the last 3 steps are the same as doing FFT on columns) finaly multiply by some normalization constant and that is all look here http://stackoverflow.com/a/22779268/2521214. Also to this http://stackoverflow.com/a/26734979/2521214 answer I added link to mine mini app where you can play with various transfroms in booth 1D and 2D (like FFT,IFFT,DCT,IDCT,...) – Spektre Feb 09 '15 at 17:55
  • @Thomas if you want learn more about FFT then look here http://stackoverflow.com/a/26355569/2521214 – Spektre Feb 09 '15 at 17:58
  • @Spektre yeah so it's because in JS I'm getting back the image as a 1D array as opposed to a 2D matrix, so was wondering if it's alright to just perform 1D FFT on it, but yeah these links are helping me understand much better! Thanks!!! – Thomas Feb 09 '15 at 18:07
  • @Thomas those links lead only to my answers. If they are not enough I am sure there are lots of better ones here on SE/SO if you search for them... (I usually link mine because they are easy to find for me) – Spektre Feb 09 '15 at 18:10
  • @Spektre I think I got it. So first I perform FFT on the original array for every single row, which generates another array with real and imaginary part. I transpose it, and perform FFT on it again, which is equivalent to doing FFT on all columns, then transpose again, while keeping in mind that the array has to be of power 2. Then I multiply by some normalization constant. So from that array I can get the phase and magnitude spectrum to show. – Thomas Feb 09 '15 at 18:24
  • @Thomas yep exactly like that ... and for view do not forget to shift/wrap the wjole thing by half size so you match the usual FFT overviews. the resolution must be power of 2 in both axises ... (lines,columns) so zeropad the rest – Spektre Feb 09 '15 at 20:01
  • @Spektre that's great! So do you know if there are any rules behind how zero padding is done? Like is it ok if zero padding is done to fill up starting from the 0th column and the 0th row, or does it have to somehow be equally spread? – Thomas Feb 10 '15 at 07:28
  • @Thomas I zero pad from end to nearest power of 2 ... so resize your image and fill the empty space with zeroes. this will not affect the result and the FFT output will stay the same as FT on original sized image. if you pad with different value or not from end then you change the phases and frequencies of the output after inverse transform you will get the original image but the frequency domain output will not match FT of the original sized image !!! – Spektre Feb 10 '15 at 08:04

0 Answers0