Fourier transforms are something that come up all the time in science, so they’re worth including here. That being said, they’re a lot more specialized than taking gradients or blurring an image, so I won’t be offended if you gloss over this part.
At their core, Fourier transforms are really simple. Taking the one-dimensional example of audio signal processing, let’s say you have some music that produces noise like this:
This pattern is a sum of sinusoidal waves, each representing the frequency of some sound. You’ll notice, however, that we don’t know any of the frequencies.
In a Fourier transform, we aim to find this information out by brute force. Simply, we multiply the above data by , where we keep varying . If our guess for does not coincide with a frequency, then the resulting output is more noise. However, if it does fit, the output function is always positive, as there is now a term kicking around.
Because I wrote this function and this is all hypothetical, I can show you what’s going on mathematically. The above noise is the sum of three sine waves,
Now, I’m going to multiply by some random values. If is 0.5, you get random stuff.
The result is sometimes positive, and sometimes negative. If you sampled a bunch of values and added them up (ie. get the area under the curve), they’d probably wash out to approximately zero.
But, if is 1.2, you get a squared sine term.
A sine wave can have positive or negative values, but any real number squared is always positive. This makes the sine wave more positive overall. So, if you added together a bunch of samples, you’d have a large positive value.
If you guess the right frequency, you have a large value. Otherwise, you have nothing. That’s it!
Let’s apply this to images. Unlike the above example, images are two dimensions. So, our sine wave has two arguments – frequency and direction. Through some basic trigonometry, our becomes , where . Now, we need to multiply the image by sine waves and add up the values. Which, if you think about it, is exactly what we were doing with convolution.
So, we can generate a sinusoidal kernel:
and convolve the kernel with an image.
This doesn’t look like much, but there is information here. The peaks in the data correspond to areas where the kernel found a pattern. In this case, my IKEA table was placed at an aesthetically pleasing 45-degree angle. which coincided with the Fourier .
Now, there are some issues here. In a true Fourier transform, the kernel would have to cover the entire image on each iteration. The data would be more conveniently plotted as a graph of vs. . A picture of my living room is a terrible example of an image that would have an interesting Fourier transform. But, I’m not going to harp on these. Why? Because, in most cases, you won’t want to directly use a Fourier transform on images. You’ll want to use the Gabor filter, which I will introduce in the next section.
But, before that, math: the Fourier transform equation.
This is slightly different from the version you’ll usually see, as I wrote out two dimensions of data. It looks complicated, but remember that is, by Euler’s formula, . Add in the fact that I have no idea how imaginary numbers would ever play a role in image processing, and the equation simplifies to what we were doing. Guess a frequency (and, in 2D, direction), multiply by a sine wave, integrate to see if it’s positive.
In the next section, we will combine the Fourier transform and the Gaussian blur to make something truly useful.