What is a photo made of?
What is a digital photo made of? The usual answer is "lots of little dots," the pixels, and that is true. But there is a completely different answer that is just as true: a photo is a pile of stripe patterns, running in different directions and with different fineness, all added together.
When the idea behind that answer was first put forward, the leading mathematicians of the day did not buy it. In 1807 Joseph Fourier, writing about how heat flows, used the claim that any function can be written as a sum of sines and cosines. The next year Lagrange and Laplace, who were judging his work, objected to exactly that point. Today the same idea is at work dozens of times a second inside your phone whenever you watch a video.
Save a photo as a JPEG and the file shrinks to a fraction of its size, yet you can hardly tell. Why? Look at a blotchy black-and-white picture, and suddenly a face pops out. Why? This simulation is a laboratory for looking at images in terms of frequency.
Building a picture from stripes
Start with sound. A musical chord is a sum of sine waves with different frequencies. An image is the same, except the waves are two-dimensional: broad stripes where the brightness changes slowly, fine stripes where it changes quickly, running in every direction. Any image whatsoever can be built exactly by adding such stripes with the right strengths and the right shifts, which are called phases. Finding them is the job of the two-dimensional Fourier transform, and the picture of the result is the spectrum. Its center stands for the average brightness, points farther out for finer stripes, and the direction of a point for the direction in which the brightness changes, which is at right angles to the stripes.
A thought experiment: begin with flat gray and add stripes one at a time, coarsest first. What do you see? A vague light and dark, then rough shapes, and only at the end the edges and fine textures. That order makes sense: an edge is an abrupt change, and it takes many fine stripes to build something abrupt. The button "Add frequencies from low to high" does exactly this. A low-pass filter keeps only the middle of the spectrum and gives a blurred picture; a high-pass filter keeps only the outside and leaves the edges.
It connects to waves in physics, too: superposition, beats and diffraction are all about adding waves. In 1873 Ernst Abbe showed that a microscope image forms in two steps: light diffracted by the specimen makes a pattern in the focal plane of the objective, and those waves interfere again to make the image. In today's language, the focal plane holds the Fourier transform of the object, and fine-stripe components that miss the lens never reach the image. That is why a microscope cannot resolve details much finer than about half the wavelength of light. Optics computes Fourier transforms for free.
How much of each stripe?
Suppose you want to know how much of one particular stripe hides in an image. The most direct approach: multiply the image by that stripe, pixel by pixel, and add everything up. A component that rises and falls in step with the stripe gives products of the same sign every time, so it piles up. A stripe with a different rhythm gives products that swing between plus and minus and cancel. Euler's formula, , lets us package a cosine stripe and a sine stripe into one number, , and then the cancellation reads
Why exactly zero when ? With the left side is a geometric series, , and . This is orthogonality. It is a bit like tuning a radio to pick out one station, except that here the periods fit the image exactly, so every other stripe cancels to precisely zero.
Do this multiply-and-add for every pair of frequencies across and down, and you have the two-dimensional Fourier transform of an image :
pixels give exactly frequencies: the same numbers seen from a different angle, so a similar multiply-and-add, the inverse transform, rebuilds the image exactly. Fourier's "any function" was a genuinely hard claim once functions need not be smooth, as we'll see below, but for an image with finitely many pixels it is literally true.
For a real image, , the complex conjugate. Since , one stripe shows up as two points, mirror images through the center. Add only one and the image is no longer real, which is why the simulation adds the mirror point for you.
An honest caveat: the transform treats the image as if it were tiled forever. If the left and right edges don't match, the seam is a sudden step, and the spectrum tends to show a bright cross. An "ideal" low-pass filter, which cuts off sharply, leaves ripples called ringing around edges, because it throws away the fine stripes needed to make them sharp.
What one point alone gives back
We saw that one stripe pattern shows up as two points, mirror images through the center of the spectrum. So what comes out if you transform just one of them back? The answer: something that isn't a picture.
The inverse transform multiplies each coefficient by a stripe with the opposite sign, , adds them up and divides by . Keep only one point from that sum and you get
Split it with Euler's formula : the real part is and the imaginary part is . Both are stripes with the same direction and the same fineness, shifted by a quarter period. Brightness on a screen is a real number, so a with an imaginary part can't be a picture by itself.
The mirror point is at the opposite frequency, so it gives . Add the two:
The imaginary parts, and , cancel exactly, and the real part doubles. You can wander through the complex numbers, but pair each point with its mirror and you come back to real stripes. The exception is a point that is its own mirror, such as the center, which stands for the DC component. Its coefficient is real to begin with, and it is added only once.
Turn on "When picking points, also show the image from one point of each pair alone (real and imaginary parts of a complex image; for comparison)" and the simulation shows the real and imaginary parts of this side by side, with zero as gray. The calculation is correct, but it is an intermediate image from before the mirror is added, shown so that you can see why the mirror is needed. With "Diagonal stripes (one pattern)" at 64 pixels, pick one point and the largest absolute values written to the right are 50.0 for both the real and the imaginary part, and 100.0 for the top-right image: the stripe's amplitude of 100 was split evenly between the two points. A word of warning while we're here: if you display the one-point image as an absolute value, the negative halves fold over as in and the stripes seem to double in number. That is only because the sign was thrown away; the stripes did not get any finer.
The doubt about "any function"
Fourier was an administrator as well as a mathematician: he went with Napoleon's expedition to Egypt in 1798, and later served as prefect of the Isère department while working on heat from around 1804. His memoir of December 1807 was examined by Lagrange, Laplace, Monge and Lacroix, and in 1808 Lagrange and Laplace objected to his expansion of functions as trigonometric series. He won the Paris Institute's 1811 prize on heat flow, but the judges complained that his analysis still lacked generality and even rigor. The Analytical Theory of Heat appeared only in 1822.
Why would heat lead to sines? In the heat equation, a sine-shaped temperature profile keeps its shape and simply fades, and finer waves fade faster. Break the starting temperature into sines and you can follow each one separately. In fact, letting heat spread through an image is exactly a Gaussian blur.
"Any function" kept mathematicians busy for a long time. Dirichlet gave the first careful sufficient conditions for convergence in 1829; Riemann, working on trigonometric series in 1854, gave the definition of the integral that university students still learn first; and Cantor's study of whether such series are unique is credited with starting him on the road to set theory. A claim about heat forced mathematics to ask what a function really is.
Doing it fast
Computed naively, each frequency takes multiply-adds and there are frequencies, so a image needs about . The idea of the fast Fourier transform, the FFT for short, is to split the samples into even- and odd-numbered ones. In one dimension, write , so that . For an even sample, , the factor is exactly the stripe of a transform of length ; for an odd sample, , it is the same thing times one extra . Calling the half-length transforms of the even and odd samples and ,
The second formula follows because and repeat every and . One pair yields two answers.
Halve, halve again: there are stages of butterflies each. In two dimensions you do the rows and then the columns, so the whole image needs only about butterflies: over two thousand times less work, the difference between a calculation that takes all day and one that is done in about forty seconds.
The FFT has a story too. In 1963 President Kennedy's Science Advisory Committee discussed how to detect underground nuclear tests; analyzing the records of seismometers set up around the Soviet Union, from outside its borders, would take enormous numbers of Fourier transforms. The statistician John Tukey had been thinking about a Fourier transform with far fewer operations, and Richard Garwin, an IBM physicist at the same meeting, saw its value and arranged for James Cooley of IBM Research to program it. Cooley and Tukey's paper appeared in 1965. Because it was never patented, it is said to have spread all the faster. Later it emerged that Gauss had written down the same idea around 1805, to interpolate the orbits of the asteroids Pallas and Juno; it was unpublished in his lifetime and appeared in his collected works in 1866. In 2000 an American computational-science journal listed the FFT among the top ten algorithms of the twentieth century.
The FFT also works out of sight. Wi-Fi and 4G and 5G networks send data on many frequencies at once, and the FFT splits the signal among them and gathers it back. CT and MRI scanners rely on Fourier transforms to turn measurements into cross-sections. The spots made when X-rays pass through a crystal are tied to the Fourier transform of its atomic arrangement, a link used to work out the shapes of DNA and proteins. MP3 and AAC audio split sound into frequencies and drop what the ear barely hears.
Eyes that miss fine color
Color can be split in a similar spirit, into a brightness Y and two color differences, a blueness Cb and a redness Cr. Your eyes are sensitive to fine changes in brightness but poor at fine changes in color. With red-green or blue-yellow stripes of equal brightness, people lose the colors at about 11 or 12 cycles per degree of visual angle, and above half a cycle per degree brightness stripes are easier to see. So the color differences can be made coarse without you noticing.
Brightness comes from the same BT.601 formula JPEG uses:
Green gets the biggest weight because the eye's brightness sensitivity peaks in the green. The numbers themselves were inherited from the 1953 color-television system described just below. The simulation's Cb and Cr pictures, which show only the color differences with the brightness held fixed, are much harder to read than a black-and-white photo for the same reason that fine color stripes are hard to see: it is mostly brightness that carries the fine detail of shapes. The scheme called 4:2:0 halves the color differences across and down. It keeps Y at 8 bits per pixel but gives Cb and Cr one 8-bit sample per four pixels, so 24 bits per pixel become .
Separating brightness from color goes back to color television. Color broadcasts had to look right on the black-and-white sets people already owned, so the brightness signal stayed as before with a color signal added on top. The U.S. Federal Communications Commission approved such a system in December 1953. Its brightness signal weighted red, green and blue by , and , the same weights that digital standards such as BT.601 give to three decimals as the , and above. A choice made for television over seventy years ago lives on in the photos on your phone.
In biology, the signals from the retina's cone cells are thought to be regrouped on their way to the brain into a brightness signal and two color-difference signals, one for red against green and one for blue against yellow. That is strikingly like Y, Cb and Cr, and it is a first step towards understanding why thinning out the color goes unnoticed.
What JPEG throws away
JPEG cuts an image into blocks and writes each as a sum of 64 cosine patterns with . This is the discrete cosine transform, or DCT. The DCT effectively mirrors each block at its edges, so no artificial step appears at the seams and the information gathers into fewer coefficients. Dividing each coefficient by a table value and rounding, , turns most fine-stripe coefficients into zeros, which pack into very little data.
The DCT came from Nasir Ahmed. The theoretically best transform for packing images, the Karhunen–Loève transform, must be computed from image statistics and is expensive. Could fixed cosine patterns come close? By his own recollection, his 1972 proposal to the National Science Foundation was not funded, and one reviewer felt the idea was too simple. He kept going with his student T. Natarajan and colleague K. R. Rao, and their 1974 paper showed it performed very nearly as well as the best transform. The "too simple" idea became the backbone of JPEG and of most video formats.
JPEG is named after the Joint Photographic Experts Group, set up in 1986 jointly by ISO and the international telecommunications body then called the CCITT; its standard was approved in 1992.
Most photos you take are stored as JPEG or a relative, and much of broadcasting and streaming combines 4:2:0 color with DCT-like transforms. While you watch a video, your device rebuilds dozens of images a second with the ideas you can try here.
Lossy compression in Informatics I does not discard information at random. It drops first what people are least likely to notice, and frequency is the language that puts "least likely to notice" into numbers.
When blots become a face
To make a Mooney image, blur a photo, then make every pixel pure black or white. The details vanish into blobs, yet once you know what is there, the object jumps out, and most people find it hard to un-see. What you perceive seems to depend on what you know and expect, not only on what reaches your eyes.
Two-tone face pictures go back to the psychologist Craig Mooney, who used them in 1957 to study children's ability to see a whole shape in fragments.
A Gaussian blur averages neighbors with weights at distance . In frequency terms it multiplies a stripe whose fineness is cycles per pixel by , a smooth low-pass filter. That is because the Fourier transform of a Gaussian is again a Gaussian; the integral is university mathematics, so we skip it.
Otsu's method chooses the black-white threshold like this. The total spread of the pixel brightnesses, measured by their variance, splits into the spread inside the dark and light groups plus the difference between the groups. The total does not depend on , so making the spread inside the groups as small as possible is the same as making the difference between them as large as possible. With the fractions of pixels in each group and their average brightness, that difference is the between-class variance
It grows with the difference of the averages, and the factor keeps it from rewarding a split that leaves one group nearly empty.
Otsu's method was published by Nobuyuki Otsu in 1979.
Otsu's method is still a standard way to set the threshold when a photo of a document is turned into crisp black and white or prepared for text recognition. In psychology and neuroscience, Mooney images are a tool for studying how knowledge and expectation help perception.
Add and remove stripes yourself
- Predict first: before pressing Add frequencies from low to high at the top of the panel, guess in what order the picture will appear.
- Drag on the spectrum in the middle to change the circle, and watch the rebuilt image on the right and the PSNR, which measures closeness to the original. Under Frequencies to keep, choose High-pass (keep outside the circle). What is left?
- Under Image, choose Diagonal stripes (one pattern). How many bright points does the spectrum show? Switch Frequencies to keep to Pick points (mirror point added) and tap one of them: its mirror point is added too, and the stripes come back. Now turn on When picking points, also show the image from one point of each pair alone (real and imaginary parts of a complex image; for comparison). Transform one point back on its own and you get a complex image of size times , where the phase grows as you move across the stripes. So the lower row shows its real part, a stripe, next to its imaginary part, a stripe. How far apart are the two? The largest absolute values written to the right show that the real part is exactly half the top-right image. The mirror point turns the other way, as , so adding it cancels the imaginary part and doubles the real part. The details are in "What one point alone gives back" under "How much of each stripe?", and the link in the panel note takes you there.
- Set Mode to Luma and chroma (YCbCr, subsampling). Compare "Chroma reduced" with "Luma reduced the same way". Which uses less data, and which looks closer to the original?
- In the Thresholding mode, choose Shaded drawing of a face and change Blur strength , which starts at px when you enter the mode. How strong can the blur get before the black-and-white picture stops looking like a face? Does Show upside down make the face harder to see?
- In the 8×8 DCT mode, press Lower the quality and watch the share of nonzero coefficients and the picture change as the quality drops.
- You can also load your own photo with Choose an image file in the Image section. It is processed only on your device.
One honest note: the spectrum is shown on a logarithmic brightness scale so that you can see anything besides the center, and when the average brightness is removed, gray means zero and the contrast is boosted. The real and imaginary parts of the one-point image also show zero as gray, both boosted by the same factor, which is written below them.
Seeing the world in stripes
An image is a sum of stripes of different directions and fineness. Multiply-and-add picks out each stripe, and the FFT made that dramatically fast. Coarse stripes carry the shapes, fine stripes the edges. Because our eyes are poor at fine color changes, the color differences can be thinned out unnoticed, and JPEG adds quantized DCT coefficients to shrink images further. And when shapes leap out of black-and-white blobs, it seems to be the brain filling in with what it knows.
An idea born in the study of heat and doubted for its rigor, made fast because someone needed to watch for nuclear tests, and joined to a transform once called too simple, now holds up your photos and your phone's connection. A last question: why do the borders of the blocks start to show when the JPEG quality drops?
Sources and further reading
The facts in this article were checked mainly against the following.
- MacTutor, "Joseph Fourier" (University of St Andrews): the Egypt expedition, the 1807 memoir and its referees, the 1811 prize, the 1822 book
- J. W. Cooley and J. W. Tukey, "An algorithm for the machine calculation of complex Fourier series," Mathematics of Computation, 1965
- IEEE Milestone, "First Demonstration of the Fast Fourier Transform (FFT), 1964" (ETHW): the 1963 science advisory committee, Garwin and Cooley
- M. T. Heideman, D. H. Johnson and C. S. Burrus, "Gauss and the history of the fast Fourier transform," IEEE ASSP Magazine, 1984
- J. Dongarra and F. Sullivan, "Guest Editors' Introduction: The Top 10 Algorithms," Computing in Science & Engineering, 2000
- N. Ahmed, T. Natarajan and K. R. Rao, "Discrete Cosine Transform," IEEE Transactions on Computers, 1974
- N. Ahmed, "How I came up with the discrete cosine transform," Digital Signal Processing, 1991: the 1972 proposal and the "too simple" review
- ITU-T Recommendation T.81 (the JPEG standard, 1992)
- ITU-R Recommendation BT.601 (the luma and color-difference formulas)
- K. T. Mullen, "The contrast sensitivity of human colour vision to red-green and blue-yellow chromatic gratings," Journal of Physiology, 1985
- C. M. Mooney, "Age in the development of closure ability in children," Canadian Journal of Psychology, 1957
- N. Otsu, "A threshold selection method from gray-level histograms," IEEE Transactions on Systems, Man, and Cybernetics, 1979
Further reading (encyclopedias):
- Wikipedia, "Fast Fourier transform": Gauss's 1805 work and why the method was never patented
- Wikipedia, "Fourier series": the later history through Dirichlet, Riemann and Cantor
- Wikipedia, "NTSC": the 1953 color television system
- Wikipedia, "YIQ": the luminance equation in the FCC rules (0.30, 0.59, 0.11) and its three-decimal form
- Wikipedia, "Ernst Abbe": the theory of image formation in the microscope