Larry Kenny -- Project portfolio

About the Random Image Generator

The Concept

If you look really closely at your computer screen, you can see that any picture is formed by hundred or thousands of tiny little dots, called pixels. Take, for example, this image:

Example picture

That image is 200 pixels wide and 100 pixels tall, for a total of 20,000 dots. The default size for the Random Image Generator is 600 by 400, for 240,000 dots. Each of the dots is set to a specific color, and that's all there is to an image. And there are only finitely many possible colors for any dot. Typically, one will find color measured in how much red, green, and blue is mixed to make the color, which each respective amount on a scale from 0 to 255. That makes for 256³ = 16,777,216 possible colors. So for a size of 600 by 400, there are exactly 4,026,531,840,000 possible images, and not a single one more.

600 by 400 is not huge, but it's not a small picture. (Back in prehistory, that was almost the biggest picture you could fit on a computer screen.) At that size, an image of me and five or ten friends would have us all perfectly discernible. If you do a Google search for "photo" and specify 600 x 400, you can see that this is more than enough for realistic detailed scenes (and keep in mind that what you're seeing in a Google search results page are shrunk-down thumbnails -- and even at that size they're still pretty clear.

So let's say, somehow, I had a folder containing every single 16-million-color 640x480 image. This would certainly take a gigantic amount of space (around 2,500 petabytes, which is a lot) but it is completely possible. One of those pictures - in fact, several of them - would be entirely indistinguishable from a photo of your face. There will be a picture of you and I eating breakfast together. There will be pictures of anybody you've ever wanted to see doing anything you've ever wanted to see them doing, and many more pictures of people you never wanted to see doing those things. There will be pictures too gruesome to describe. There will be a picture of your future.

Of course, the vast majority of the pictures will look like color television static. Four trillion is a huge number of possible images. That's about how many carbon atoms would fit in the period at the end of this sentence. It's about a third the size of the dollar value of the 2011 United States national debt. It's huge. So perhaps storing that many images is impractical and horribly inefficient. But how about generating them? That's the idea behind this toy - every time you click "New image", you get a randomly generated one of these trillions of possible images. It could be anything.

By the way, you can change the size of the image generated. In case you were worried that an image of your future soulmate would appear and the resolution would be insufficient to tell who it was. The size is listed in the URL. For example, here is a smaller square version.

The algorithm

At first, I had a random image generator in the most straightforward way - it assigned a random color to every pixel. This was fun for a while, but after generating a few dozen images, the statistical reality dawned on me - I could sit here generating images for weeks without standing a remote chance at seeing something other than colorful dirt. I thought for a moment about what made images interesting to humans, and decided that to make the image generator more interesting, it should be biased toward larger areas of more solid colors. So I set out to add an interestingness-enhancing filter. The image is still random - any image could appear - but the distribution is changed; now some kinds of images are more likely than others.

First, a completely random picture is generated as the base image. Then the filter works roughly as follows: A random number of pixels are selected at random, and within a radius of random length around each of these pixels, that pixel's color "bleeds" onto the surrounding pixels, with its opacity decreasing with distance according to one of three functions (selected at random). Then this process is repeated a random number of times.

It should be noted that these "randoms" could be random positive integers from a uniform distribution, random real numbers from a Gaussian distribution, or some product of the two. Anybody interested in seeing the actual messy code can find it here.


For fun, mostly. Even if the odds of seeing anything that remotely looks like anything are vanishingly slim, some of the images that come up are pretty cool. Especially if you listen to while noise and stare at them in the dark, and see what you can see in them. And there's always the possibility, however unlikely, that you're going to press "New image" and be greeted with a written command clearly discernible amidst the static - and if that happened, would you dare disobey it?

Depending on interest or desire to not work on more important things, I'd like to try some new algorithms - perhaps something that starts with random solid shapes rather than a random field of static. It might also be fun to allow users to save images they like, view and thumbs-up or down other users' images, or even feed the "good images" back into the algorithm as a from of genetic programming to see what it learns. For now, it just makes neat ink blots.