131
$\begingroup$

I was just learning about the frequency domain in images.

I can understand the frequency spectrum in case of waves. It denotes what frequencies are present in a wave. If we draw the frequency spectrum of $\cos(2\pi f t)$, we get an impulse signal at $-f$ and $+f$. And we can use corresponding filters to extract particular information.

But what does frequency spectrum means in case of images? When we take the FFT of a image in OpenCV, we get a weird picture. What does this image denote? And what is its application?

I read some books, but they give a lot of mathematical equations rather than the physical implication. So can anyone provide a simple explanation of the frequency domain in images with a simple application of it in image processing?

$\endgroup$
5
  • $\begingroup$ in this context a very nice demo: bigwww.epfl.ch/demo/basisfft/index.html $\endgroup$
    – Dov
    Commented Mar 9, 2012 at 3:45
  • 6
    $\begingroup$ The best way to understand what a transform does is to play around with feeding simple inputs to the inverse transform. $\endgroup$
    – endolith
    Commented May 13, 2013 at 21:07
  • 1
    $\begingroup$ See also this interesting explanation by Steve Eddins blogs.mathworks.com/steve/2009/12/04/… $\endgroup$ Commented Nov 8, 2015 at 13:19
  • $\begingroup$ @endolith Yeah! you need some knowledge on domain beforehand to fully understand what is happening and why it is happening.. $\endgroup$
    – Learner
    Commented Apr 9, 2016 at 9:29
  • $\begingroup$ dear the frequency domain of the image represent the power intensity in watt with respect to the certain frequency in hertiz such as (dc component, low frequency and high frequency) $\endgroup$
    – mntaser
    Commented Feb 27, 2017 at 22:23

5 Answers 5

108
$\begingroup$

But what does frequency spectrum means in case of images?

The "mathematical equations" are important, so don't skip them entirely. But the 2d FFT has an intuitive interpretation, too. For illustration, I've calculated the inverse FFT of a few sample images:

enter image description here

As you can see, only one pixel is set in the frequency domain. The result in the image domain (I've only displayed the real part) is a "rotated cosine pattern" (the imaginary part would be the corresponding sine).

If I set a different pixel in the frequency domain (at the left border):

enter image description here

I get a different 2d frequency pattern.

If I set more than one pixel in the frequency domain:

enter image description here

you get the sum of two cosines.

So like a 1d wave, that can be represented as a sum of sines and cosines, any 2d image can be represented (loosely speaking) as a sum of "rotated sines and cosines", as shown above.

when we take fft of a image in opencv, we get weird picture. What does this image denote?

It denotes the amplitudes and frequencies of the sines/cosines that, when added up, will give you the original image.

And what is its application?

There are really too many to name them all. Correlation and convolution can be calculated very efficiently using an FFT, but that's more of an optimization, you don't "look" at the FFT result for that. It's used for image compression, because the high frequency components are usually just noise.

$\endgroup$
13
  • 3
    $\begingroup$ can you specify which is highfrequency part and which is low frequency part in frequency domain image? $\endgroup$ Commented Mar 6, 2012 at 16:40
  • 4
    $\begingroup$ @arkiaz: In the images I've shown, the highest frequency is in the center of the image, lowest frequency (i.e. the mean of the input image) is top left pixel in the FFT result. That's what most FFT implementations give you. If you display the FFT result, it's common to move the lowest frequency to the center of the displayed image. $\endgroup$ Commented Mar 6, 2012 at 17:50
  • 1
    $\begingroup$ @Mohammad: I've used Mathematica's InverseFourier function. Doesn't octave/matlab's ifft2 do the same? $\endgroup$ Commented Mar 7, 2012 at 7:21
  • 7
    $\begingroup$ These would be great as animations, like move the point around and show how the waves change width and angle $\endgroup$
    – endolith
    Commented May 9, 2014 at 20:11
  • 2
    $\begingroup$ Is it only me who thinks that it would have been much more intuitive and easier to understand if the transform examples were given (or taken as) from spatial domain (images that makes sense to humans) to their frequency domain equivalents? $\endgroup$
    – 0xc0de
    Commented Dec 28, 2017 at 8:47
42
$\begingroup$

I think this was put very well in the well known "DSP guide" (chapter 24, section 5):

Fourier analysis is used in image processing in much the same way as with one-dimensional signals. However, images do not have their information encoded in the frequency domain, making the techniques much less useful. For example, when the Fourier transform is taken of an audio signal, the confusing time domain waveform is converted into an easy to understand frequency spectrum.

In comparison, taking the Fourier transform of an image converts the straightforward information in the spatial domain into a scrambled form in the frequency domain. In short, don't expect the Fourier transform to help you understand the information encoded in images.

So there is, of course, some structure and meaning behind the seemingly random pattern obtained by taking the DFT of a typical image (such as the example below), but it is not in a form that the human brain is prepared to understand intuitively, at least regarding visual perception.

Imgur

Here is another interesting and quite readable exposition of what is contained in a Fourier transform of an image, and how it can be interpreted. It has a series of images that make it quite clear what the correspondence is between the Fourier-transformed and the original image.

edit: take also a look at this page, which demonstrates —near the end— how most of the perceptually important information of an image is stored in the phase (angle) component of the frequency representation.

edit 2: another example of the meaning of phase and magnitude in the Fourier representation: "Section 3.4.1, Importance of phase and magnitude" of TU Delft's textbook "Fundamentals of Image Processing" demonstrates this quite clearly:

Imgur

$\endgroup$
3
  • $\begingroup$ Hey! I tried following the second link in your question ("another interesting and quite readable exposition...") but the link is not working. I also tried the link provided in the comments, but does not work. Could you find and edit in a working link please? $\endgroup$
    – penelope
    Commented Jan 14, 2014 at 10:36
  • $\begingroup$ @penelope you're the second person to notice problems with the link (see my previous comment). The page seems to be unstable, indeed. As I said previously, I'll replace the link with the Web Archive version. Thanks for pointing this out! $\endgroup$
    – waldyrious
    Commented Jan 16, 2014 at 3:47
  • 1
    $\begingroup$ Actually, the examples and explanations at the (finally working) link are great :) $\endgroup$
    – penelope
    Commented Jan 16, 2014 at 8:58
13
$\begingroup$

The wave $f(t)=cos (ωt)$ is a one-dimensional wave; it depends only on $t$. The wave $f(x,y)=cos(ωx+ψy)$ is a two-dimensional wave. It depends on $x$ and $y$. As you see, you have two frequencies, in either direction.

Therefore, the fourier transform (FFT) of $cos(ωx+ψy)$ will give you $ω,ψ$, just like the FFT of $cos(ωx)$ gives you $ω$. And if your input is a function summing 2D cosines, then your 2D FFT will be the sum of the frequencies of those cosines - again a direct analog of the 1D FFT.

$\endgroup$
0
10
$\begingroup$

It may be worth noting that Fourier Analysis is a special case of a concept called orthogonal functions. The basic idea is that you break down a complicated signal into a linear superposition of simpler "basis" functions. You can do your processing or analysis on the basis functions and then sum the results for the basis functions to get the result for the original signal.

In order for this to work there are certain mathematical requirement for the basis functions, i.e. they ideally form an orthonormal base. In case of the Fourier Transform the basis functions are complex exponentials. However, there are many other functions that can be used for that as well.

$\endgroup$
5
  • $\begingroup$ Thats true. What other types of basis functions are there? I am thinking daubechies wavelets, but are there other ones too? What would differentiate them? $\endgroup$
    – Spacey
    Commented Mar 8, 2012 at 23:39
  • $\begingroup$ Probably the best known are the polynomials; the representation of a function as a set of polynomials is known as its Taylor serie. This serie is easily calculated from the function derivatives. $\endgroup$
    – MSalters
    Commented Mar 9, 2012 at 9:22
  • 2
    $\begingroup$ One way to find basis functions is applying Principal Components Analysis. The resulting 'eigen-images' often have a more human-intuitive appearance than sin/cos functions. For an example, see Eigenfaces. The frequency domain is still relevant for perception (our eyes/brains have edge-detectors that are sensitive to frequency, particularly when motion is involved); the basis functions are just not very meaningful as images. $\endgroup$
    – Dan Bryant
    Commented May 16, 2013 at 13:40
  • $\begingroup$ PCA is a nice basis computation technique that's widely understood, but there are many others that make different assumptions about how the data was generated; Independent Component Analysis (ICA) is one popular example. A bit further afield, there are algorithms for generic basis function learning using sparse coding (e.g. J Mairal et al., "Online dictionary learning for sparse coding," ICML 2009), and then the "feature learning" approaches developed by the deep nets folks. $\endgroup$
    – lmjohns3
    Commented Aug 22, 2013 at 22:17
  • 1
    $\begingroup$ Why do the functions have to be orthogonal? $\endgroup$
    – quantum231
    Commented Sep 27, 2014 at 20:39
8
$\begingroup$

In images increasing frequency is associated with more abrupt transitions in brightness or color. Furthermore, noise is usually embedded in the high end of the spectrum, so low-pass filtering can be used for noise reduction.

$\endgroup$
2
  • 1
    $\begingroup$ so you mean abrupt transitions are sometimes regarded as noise? $\endgroup$ Commented Mar 7, 2012 at 14:53
  • 1
    $\begingroup$ Yes, sometimes. Common examples include mosquito noise (ringing around edges), JPEG block noise at the edges of the macroblocks and, of course, grain. Consider an image of a simple gradient. Adding grain to this image increases its high-frequency content by introducing minute transitions throughout the image. $\endgroup$
    – Emre
    Commented Mar 8, 2012 at 1:12

Not the answer you're looking for? Browse other questions tagged or ask your own question.