Saturday, December 13, 2008

Gaussian stuff

A while ago, in a blog far, far away, I posted a bit about the Gaussian distribution, and how it can be used for blurring images, as in Photoshop’s Gaussian blur function. What the Gaussian distribution really is is a way of describing the probabilities of certain kinds of events. For example, suppose your wondering about rainfall in New York City, and you want to know how much rain is falling on different parts of the city during a storm. Well, chances are that all of New York is getting socked, and the rainfall amounts are probably pretty even all over. If there’s an inch of rain, there’s going to be an inch of rain on Wall St., and inch on 14th St., and inch on 42nd Street, and so on going uptown from the Battery to Harlem.

This is what’s called a flat distribution … the rainfall amount is flat regardless of how far North you go. If you graphed rainfall amount against latitude, South to North, across Manhattan, your graph would look something like this:

But, if we were talking about how much rain falls on New York in a typical rainstorm, we might get a graph like this:

This shows that there's some amount (I have no idea what it actually is) that is the average rainfall for a storm in New York. Most storms dump roughly this amount of rain, so there's a hump in the middle of the graph, right around the average. Some storms dump less and some dump more, so the number of storms gets less and less as you get further from the average in either direction.

So, what does the rainfall in New York have to do with art and technology? Nothing, but the interesting thing is the shape of that Gaussian distribution, often called a bell curve, for obvious reasons.

I talked about using this for blur, but it's useful for other kinds of effects. For example, think about how an airbrush works. It sprays a stream of very fine droplets of paint, and they land mostly along a line traced by the airbrush. A lot of paint also falls just to one side or the other of the line, and a little bit less falls a little further away. In other words, the amount of paint is like a Gaussian distribution, with most falling along the path of the airbrush, and less and less paint as you get further and further from this path. That's how airbrushes give that nice soft edged look.

This may be kind of light (Click on the images for a larger view.), but it shows that the center of the stroke is darkest, and the line gets gradually lighter near the edges. Here are some more examples, drawn by a PostScript program that creates random curves, and then applies a kind of airbrush effect with the Gaussian arrangement of dots of color:

2 comments:

demichou said...

Very interesting indeed ! I always thought Postscript was limited to spline graphics. I will be happy to have a look at your Postscript code !

Peter Davis said...

For the airbrush effect, you can find the PostScript code at:

http://www.pfdstudio.com/PostScript/AIRBRUSH.PS