Yeah, okay. That was neat I guess. But I couldn’t come up with any other shapes that worked. But all this thinking about histograms and what they represent got me wondering if I could control what a histogram looks like by manipulating the image. Could I create something recognizable? To try it, I would need to find something that would be entirely black, horizontal in orientation, and not require any holes or vertical gaps. A skyline seemed perfect.

The idea for this project started with a question: Is it possible to create an image that depicts its own histogram? (A histogram, for those unfamiliar with the term, is a bar graph representing all the tones in an image — it typically looks something like a mountain range). I played around a little bit in Photoshop and the closest thing I came up with was this image:

Several people have asked how I did it. So I’ll explain, but I might get a little longwinded in my attempt to be clear. Feel free to just skim and look at the pictures if you don’t want to read it all.

Yesterday, I posted the image seen here and told you that there is another picture hidden somewhere within it. I challenged my readers to find it. After a bit of confusion in the comments, someone finally declared that they found it: “Hahahaha! Cool! It’s the NY skyline!” Another reader noted, “The first thing I did was to try to tweak the image using the Levels command. I was greeted with a surprise right there in the dialog.”

I did a Google Image Search for “manhattan skyline silhouette” and was tickled to see that the perfect image came up in a result from my own site! I once posted an entry about New York City as depicted in the animated film Antz. Google showed me this image from that entry on the first page of search results:

A typical 8-bit grayscale image can have 256 possible shades of gray. A histogram represents the amount of pixels at each level from 0 to 255, and is 256 pixels wide. So the first thing I did was shrink down the Antz skyline to 256 pixels wide. This meant that each vertical band of black pixels in the skyline represented a value from 0 (black) to 255 (white).

Then I created a new document. The first column of pixels in the skyline image represents value “0” and has 43 black pixels. So my new document needed 43 pixels with the value “0.” Column 2 of my skyline represents value “1” and has 46 black pixels. So my new document needed 46 pixels with the value “1.” And so forth.

Another way to think of it is to say that I took all of the “skyline” pixels from this image:

…and put them in a new document, with no other pixels. Then I rearranged all those pixels into a square from dark to light. The result was very close to perfect. The histogram looked pretty much like the skyline, but it was stretched vertically.

Normally, a histogram is scaled vertically so that whatever value has the most pixels reaches all the way to the top of the graph, and everything else is sized proportionately. In this case, it is the shade of gray which forms the World Trade Center antenna that has the most pixels. So this is roughly what the histogram looked like:

I was thrilled that it worked, but I didn’t want it stretched vertically like that. In order to prevent the WTC tower from being too tall (and everything else scaling upwards with it) I had to put extra pixels of one value in my image, so there would be more pure of that value than any other value, which would push the others down so that the graph remains proportionate. I chose pure white, because this creates a thin black line at the far right side of the histogram where you don’t notice it.

I could have added this row of white pixels at the bottom of the new image, but instead I typed my website name in white, and placed it within the image. In doing so, I copied over some other pixels, which altered the skyline. So I had to put it in a place where the “damage” to those buildings wouldn’t be that noticeable. It took trial and error, but I found a good spot. It changed the skyline on the left side a little bit (compare to the “Antz” image). But it still looks like buildings, so I accepted it. Also, this way I get some credit if the image gets passed around without attribution.

I did it all tediously by hand, but I think with a little tinkering, someone could write a program to simplify the process, taking a 256 x 100 silhouetted image and extrapolating a new image with that as the histogram. And the final image file doesn’t need to be a square with a gradient, either. Those pixels could be in any order. They could be completely scrambled. Or they could be laid out in a way that shows an image of an Apple (as in “The Big Apple”). As long as no new pixels are introduced or deleted, the histogram remains the same. But that is a lot more work than I was prepared to do.

Oh, I almost forgot: I doubled the image size so it would look a little better on the website. As long as I resized it using the “Nearest Neighbor” method instead of some other interpolation method, every pixel (and therefore every shade represented in the image) would be duplicated identically, keeping the proportions in the histogram the same.

Update: A reader has taken this idea even further!