Lenny Domnitser’s

⇙ Jump to content


This is a static archive of the domnit.org blog,
which Lenny Domnitser wrote between 2006 and 2009.

Facebook Friend Mosaic

I made an application that makes a photo mosaic from Facebook pictures. It uses your friends’ profile pictures as tiles, and the picture formed is your profile picture. Here’s an example:

(example mosaic)

Unfortunately, the app uses too many resources to feasibly release it to the public on my shared server. It works today, just behind a password wall. If you want to use it and I know you, just email me.

So what good is this private use only app? Well, some open source software is coming out of it:

  1. I didn’t need the big Python Facebook library, so I made a tiny one that’s suitable for just dropping in to your code. That’s coming later today. (It’s available now if you know where to look.)
  2. The mosaic code will probably be released next week. I must first make it more generic, and make some human interface, since it won’t be connected to the Facebook app anymore.

Making mosaics turned out to be quite simple. After building an index of tile images and their average colors, the big image is scanned section by section, and the closest-matching tile is pasted over that section. The only interesting question is what closest-matching means, given an average color for the section we are looking at and for each possible tile.

To compare two colors ((R1, G1, B1), (R2, G2, B2)) for closeness, I use the formula (R1R2)2 + (G1G2)2 + (B1B2)2.* Each channel difference is squared because it makes the number positive, and punishes bigger differences in a single channel, so a color which decently matches in all channels will be considered better than a color which matches very well in one channel but poorly in another. Lower numbers mean a better match, with 0 as the best, and 3·0xFF2 as the worst.

This formula was the first thing I tried, and it gave good results, so I didn’t mess with it.

* This mathematical notation is readable without having to think about it much, but the Python is more elegant. sum(difference ** 2 for difference in (channel[0] - channel[1] for channel in zip(rgb1, rgb2))) expresses the same formula if RGB is used, but it also works on any number of channels, so it can be used as-is with any color mode.

1 comment on Facebook Friend Mosaic

1. Jordan Waddell says:

Hey. Awesome idea. how can i get the mosaic?

—Jordan Waddell, 8 October 2007, 14:36

Comments on this entry are now closed. Thanks to those who participated. You can still email me.