9
$\begingroup$

I have some questions about this interesting concept I came across about 2D Fourier transform, please...

Firstly, the Fourier transform of a 1D signal (such as a sound recording) is as follows:

enter image description here

The first picture is a graph of the real sound file, and the second picture is the sorted frequency bins of the analysed original recording. Although the the graphs are often plotted next to each other, the frequency domain graph really is not at all related to space dimensions, as it has no relations at all to the physical shape of the sound waves (or images file) etc. It is just a histogram of the strength of the different frequencies found after analysis, from bin 1, 2, 3... into a chart.

But, when we come to the 2D Fourier transform for images, suddenly I have trouble even picturing what this might possibly mean?

enter image description here

What is meant by the Fourier transform of a 2D signal? Do we take many 1D Fourier charts in the x-direction as before and do another meta Fourier transform in the y-direction on these frequency charts?

Since frequency charts are not even about spatial relationships, but really about histograms of tabulated frequencies, what does the frequency picture even represent? How to calculate the color value for each of the point $(x,y)$ in the frequency image, and what does the $x$-axis represent, what does the $y$-axis represent in this frequency image?

EDIT: Forward Fourier transform results

enter image description here

$\endgroup$

2 Answers 2

10
$\begingroup$

Yeah, this can be tricky to wrap your head around! Let's simplify. I can't guarantee you'll ever have an intuition for your more complex transforms. But after reading this, hopefully you'll have a place to start.

Here is a cosine wave, $\cos(x)$, 5 periods discretized into 101 points (since images on your computer are discrete, let's work with discrete data here). The x-axis is just the point number, not $x$. To the right is the absolute value of its discrete Fourier transform, $F(\cos(x))$ (I used the Mathematica default options for this).

enter image description here

We can interpret the peaks in this transform as the frequencies which comprise $\cos(x)$, one at positive frequency, and one at negative frequency. Since there are five periods within the range on the left, the transform peaks occur on the fifth points from the left and right (actually, the sixth point from the left including the zero frequency point). If the wave had a higher frequency, then there would be more periods within the range, and the transform peaks would appear further from the left and right, respectively.

Okay, now here's the 2D version of the same plot, along with the 2D Fourier transform of the image (absolute value, again):

enter image description here

You'll notice, at the very bottom of the transform image, two blips corresponding to the peaks in the first image. How do we interpret this? Well, again, the peaks represent the frequencies comprising $\cos(x)$. Since now we're plotting $\cos(x)$ in the $x$-$y$ plane, the fact that the peaks occur at the very bottom indicates that the image is constant in the $y$ direction (i.e., the only existing frequency in that direction is zero).

Here's what it looks like if we plot $\cos(y)$ instead:

enter image description here

Okay, cool. Now, generally in 2D, a wave could propagate in any direction within the $x$-$y$ plane, with any frequency: $\cos(k \cdot r)=\cos(k_x x+k_y y)$. So here is $\cos(x+y)$:

enter image description here

And here's $\cos(x+3y)$:

enter image description here

Of course, in the end, a complete image will be comprised of a linear combination of waves with all the wavevectors. Any image can be broken down this way. Here's $\cos(x+y)+\cos(x+3y)+\cos(3x+2y)$:

enter image description here

So what do I mean by "frequency" in all of this? I mean the number of periods which fit within the range of the image in a particular direction. In your first plots, the 1D example, the axis is understood to be representative of time. Therefore, the frequencies of the transform are temporal frequencies. However, if the axis were in units of length, the transform would show spatial frequencies. Since images are often in units of length, then the 2D transform is often interpreted as the spatial frequency spectrum which comprises the image.

$\endgroup$
7
  • $\begingroup$ @ Gilbert thanks! I have done a bit more work since, I could do the forward transform now (will show picture in edit) using this homepages.inf.ed.ac.uk/rbf/HIPR2/fourier.html . But i still don't know how to reconstruct the original image from this. Here's a toy example, though. Suppose the image of size 4x4 is: [[1,2,1,2],[2,5,4,3],[6,4,3,2],[1,3,2,1]]. Could you perhaps demonstrate a simple hand/computer code for calculating the complete 4x4 Fourier frequencies of these entries, then the code to reconstruct back the original numbers exactly using inverse Fourier process, please? $\endgroup$
    – user315366
    Commented Dec 17, 2021 at 18:54
  • 1
    $\begingroup$ @James well one thing I glossed over is the fact that Fourier transforms are complex, meaning that any transformed image you see does not contain all the information needed to reconstruct the original. In my answer, I’m showing the absolute value of the transform, which is a common choice, but you really need both amplitude and phase for every point in order to inverse transform back to the original. If you’ve done the transform yourself, then you have all the info. $\endgroup$
    – Gilbert
    Commented Dec 17, 2021 at 19:04
  • $\begingroup$ @ Gilbert thanks, i'll try it! $\endgroup$
    – user315366
    Commented Dec 17, 2021 at 19:10
  • 2
    $\begingroup$ Do you have access to scientific computing software such as MATLAB, Mathematica, or Python with the NumPy package? Any of these can trivially transform and inverse transform your images. Like I said, though, the transforms are complex valued. $\endgroup$
    – Gilbert
    Commented Dec 17, 2021 at 19:16
  • $\begingroup$ @ Gilbert thanks, yes i am doing it from scratch this time on purpose to try understand it first $\endgroup$
    – user315366
    Commented Dec 17, 2021 at 19:25
4
$\begingroup$

I'll give you a mathematical expression to augment Gilbert's answer. The Fourier transform in 1D is given by $$\hat f(k)=\int\mathrm dx \, e^{ikx}f(x).$$ There are ofcourse other conventions but I chose a convenient one. You can then consider a (grayscale) image as a 2D function $f(x,y)$ which gives the intensity of the image at every point $(x,y)$. The Fourier transform in 2D is given by $$\hat f(k_x,k_y)=\int\mathrm dx\,\mathrm dy \, e^{i(k_xx+k_y y)}f(x,y).$$ The output is, just like $f(x,y)$, a two dimensional function. So the output is again an image! This image will generally be complex so to show this image often the absolute value is taken of the output. Also the log is often taken to bring out details with low intensity. It looks like this happened for your images as well but I'm not sure.

For implemnting this on images you can have a look at the discrete Fourier transform. Note that depending on the implementation the $(0,0)$ might end up either in the corners or in the center of your image. If you want to use the discrete Fourier transform a lot you should always use a library/predefined function because there exists an algorithm to compute the discrete Fourier transform called the Fast Fourier Transform which, like the name implies, is much faster.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.