How to Graph Any Picture

Cat Pace
7 min readJun 14, 2019

--

If ever you have a bored minute, I’d recommend an unusual form of entertainment. It resides on an otherwise academic, mathematics-laden website known as Wolfram Alpha.

Type “Banana curve” into the search bar.

For those with more demanding artistic sensibilities, you might want to try “Severus Snape-like curve.” Or there’s always the “first” and “second” “Albert Einstein curves.” And if you aren’t inclined to put in the extra seven seconds of work to satisfy your curiosity, here’s a picture of the “Simba-like curve”:

(http://m.wolframalpha.com/input/?i=simba+curve&x=0&y=0)

Math doesn’t seem so unartistic now, does it? But how, exactly, does one pull off these visual feats with only graphing software and the human brain?

The Basics of Mathematical Imagery

At its core, a coordinate graph is a visual representation of the relationship between numbers or variables. But this works the other way around, too: The formulas are a mathematical representation of the images they produce when graphed. This perspective suddenly offers a whole new slew of possibilities, as images can now be produced with only numbers, symbols, and graphing software.

This might sound familiar to a designer or digital artist. Doesn’t vector illustration software, like Adobe Illustrator, rely on math? Yes, and in many ways, it’s a similar idea. The user inputs an image, be it a simple line, some typography, or a complex sketch, and the program stores this image as mathematical equations and geometric shapes.¹ This reliance on mathematics is what makes vector illustrations infinitely scalable.

This brings us to a simple example of generating an image with a graph: the batman curve. This image was popular on the internet in the good ole’ days, way back in 2011. But despite its outdated nature as a meme, it serves as a timeless example for how combining mathematical functions can create an aesthetically recognizable and even attractive image. The original creator of the graph was a high school teacher, J. Matthew Register, who aimed to inspire his students about math.

(http://santacruzmathguy.tumblr.com/image/8270375482)

When breaking down the equation, each of the terms in parentheses represents a different set of lines in the batman graph. For example, the very first term (the chunk of variables in the first parentheses) is the bat’s outer wings, based on the general formula for an oval. Unlike graphs that you study in Algebra in high school, which extend forever, these lines are manipulated using mathematical concepts such as imaginary numbers. This batman equation cannot be graphed on a run-of-the-mill graphing calculator. It was designed for a more robust graphing software, called Mathematica, although the TI-89 can still draw some pretty robust pictures (see related links below).

In theory, this graphing method can be used to generate any significantly simplified image on a coordinate grid. However, it’s time consuming and subjective — Mr. Register cites a five or six hour time frame for creating his original equation.

Trigonometric Functions Make It Possible

But there is another way, one that makes the complex Wolfram Alpha illustration curves, such as the “Simba-like” curve above, possible. It’s based on something called the Fourier Transform. This tool is used to write any function as a sum of sine and cosine functions. I was originally introduced to the Wolfram Alpha graphs and the basics of the math behind them by my AP Physics professor, another teacher who, like Mr. Register, cared deeply about the educational experience and fundamental understanding of his students.

The Fourier Transform is an extension of the Fourier Series, a calculus concept that explains how any periodic (AKA repeating) function can be written as a sum of sines and cosines. In fact, many functions require an infinite number of sines and cosines. It turns out that sines and cosines can be useful beyond just exasperating trigonometry students; the study of Fourier Series and ways of manipulating them is an entire field of mathematics, known as harmonic analysis. The Fourier Transform was discovered by Jean Baptiste Joseph Fourier, who in 1822, after a series of papers, published a book on the mathematics of heat. He was the first person to mathematically represent heat diffusion; he was also the inventor of the notation for definite integrals.²

Fourier Series approximate a function, and each “step” in the process — each additional sine or cosine function — brings the approximation closer to whatever function is being replicated. Add another sine or cosine, achieve a more realistic “image.” This is why the series can be infinite; the approximation gets better and better without ever truly becoming accurate. The whole process looks something like this:

(https://giphy.com/search/fourier)

The Fourier Transform is a mathematical tool related the Fourier Series. The transform decomposes a function into a set of sinusoids, or periodic functions. This comes in handy because these periodic functions can then be written as sines and cosines using the Fourier Series. Yes, you read that right: Any mathematical function can be created by adding up variations of sin(x) and cos(x).

The Fourier Transform is rife with practical applications in science and engineering, particularly because the real world has fewer problems of continuity and convergence than theoretical mathematics. And once you can use the Fourier Transform to turn any function into sines and cosines, well, infinity’s the limit (just kidding, the limit of sin(x) as x goes to infinity does not exist).

To take the bizarre ubiquity of sines and cosines even further, a graph is not the only thing that can be converted to sinusoids using the Fourier Transform. The mathematical tool is also used in processing pixel-based images. To understand how this is possible, one must return to the basics of what a periodic function is. The generic form reads like A sin(bx)+c, where each coefficient (A, b, and c) describes a different characteristic of the graph. In this format, A is the amplitude, b tells you the period, and c is the phase shift. By using analogous information, the pixels in an image can be “encoded” into a sinusoidal function. For example, a pixel’s “intensity” corresponds to the amplitude (A) of a sine function, while the pixel’s “location” is the phase shift (c).³

In this manner, the Fourier Transform creates a unique representation of the whole image. There’s only one Fourier Transform for every image, and vice versa, only one image for every Fourier Transform. In essence, every digital image ever created corresponds to a string of sinusoids; this mathematical tool is just as rich and varied as digital photography and art.

Mathematical Art and Artistic Mathematics

If you look back at any of the Wolfram Alpha picture curves, you will see that the equations were dizzyingly long lines of — you guessed it — sines and cosines. The Fourier Transform makes all of those graph images possible. And the fascinating thing is that in the end, this small subset of mathematics is after the same thing as many parts of art and design: finding the best representation of a visual phenomenon. The specifics differ wildly, but perspective tricks and line weights are tools in much the same way calculus and cosines are.

Beyond the novelty graphs on Wolfram Alpha, there have been a few attempts to harness the Fourier Transform for more artistic purposes. One of the more fascinating I found was an (apparently obsolete or never-released) how-to-draw app called “DrawAnything.” The app attempted to teach its users how to draw any uploaded image, using the Fourier Transform. Each “step” in the app’s generated how-to-draw tutorial would be a step in the Fourier Transform approximation. The idea is a good one — marry math and drawing, go from simple to complex the same way one would draw anything. It is clear, however, that it was developed by someone more interested in Fourier Series than in drawing, because the simplest phase of a Fourier Series looks nothing like the way a drawing is typically constructed.

Sines and cosines are unlikely to magically turn any artist into a math nerd, just like a pretty graph is unlikely to magically turn any mathematician into a painter. But sinusoids are far more beautiful than one might expect. In essence, every painting, photograph, or scene that has inspired you is one Fourier Transform away from being an equation on a screen. They say a picture is worth a thousand words; I’m not sure who they are, although I’ll bet they’re paid to draw things. But if it is the case that a picture is worth a thousand words, then, well, so is a function. They match up, after all — line by line, pixel by pixel.

Still Curious?

If you’re fascinated just by observing these Fourier Transform graphs, there’s a lot more where that came from. Try the Wolfram Alpha page about Popular Curves here, or see a complete list of the named curves on Wolfram Alpha here.

To see a full, detailed explanation of the Batman-curve development process, see Mr. Register’s original blog posts here, or another walk-through of the process here.

For a batman equation that can be graphed on a standard TI-89 calculator, along with TI-89 equations for many other images, try here.

For a beautifully clear in-depth explanation of the Fourier Transform, and much of the related math, check out http://www.thefouriertransform.com/.

--

--

Cat Pace

I empower people to understand brand strategy that's why-driven, systems-based, and people-first. Founder of Ninth Life Insights LLC.