« Google's book grab | Main | The return of eDay »


Some people make them out of toast, some use newspaper clippings and some even use toothpicks but Linux users have it easy. When it comes to making mosaics, all you really is Metapixel.

Metapixel is a command-line tool that creates photomosaics -- pictures in which the original image is rebuilt using a series of much smaller images. The effect can be stunning ...



... when you look closely ...


(Check out this link to see the original in its full glory.)

You need two things to turn an picture into a mosaic; a source image -- obviously -- and a library of "tiles" from which to build the final picture. But first, the software ...


Installing Metapixel
Ubuntu and Debian users can simply open a console window and type:

sudo apt-get install metapixel

Other Linux users should check their repositories. Metapixel seems to be a standard addition, but if all else fails check out their homepage.


Creating a tile library
This single-stage process actually does two things; it scales images down to a manageable tile size and computes various factors that will be used to match pixels in the source image. The bigger the source library, the better, and in Linux we have an ideal one in /usr/share/icons.

First, create a new directory in which to store the tiles:

mkdir tile_library

Then tell metapixel to populate it:

metapixel-prepare -r /usr/share/icons tile_library --width=32 --height=32

The switches:
  • -r tells metapixel-prepare to recurse all sub-directories under /usr/share/icons.
  • tile_library is our newly created tile directory.
  • --width= and --height= set the width and height of the tiles. (I find the default, 128x128, a little too large!)
Notes that Metapixel only recognises JPG, PNG and GIF files, anything else generates an error message and is ignored. After several minutes processing, I found my library filled with more than 10,000 "tiles". Perfect!


Creating Mosaics
Now for the fun bit. Building a mosaic is as simple as typing ...

metapixel --library tile_library --metapixel original.jpg target.jpg

... but depending on the size of your original, the results may not be too spectacular. Allow me to demonstrate. Here's my original:





(It's the 128x128 pixel penguin.png icon given
a white background and renamed penguin.jpg.)



And here's the result :




When you think about it, it's not too surprising. We're mapping 32x32 pixel tiles onto a 128x128 pixel image. The most we're ever going to get is four tiles across and four down!

There are two solutions. The first is to use smaller tiles. We can force this be declaring their height and width:

metapixel --library tile_library --metapixel original.jpg target.jpg height=8 width=8

This produces a much more satisfactory result:



The other alternative is to use the "scale" parameter to resize the original before the tiles are applied.

metapixel --library tile_library --metapixel original.jpg target.jpg -s 20

will scale 20x, meaning Metapixel will work from a 2560x2560 image -- and generate one of that size! Here's the result, squeezed down to a mere 400x400 to fit on this page:


(To study it's full splendour, just click on the image.)

You can of course combine both scale and height/width parameters for even more detail.

There's one other option to be aware of. By default Metapixel produces "traditional" mosaics that use evenly spaced tiles, but add the --collage parameter and it will overlay them to get the best resolution. Here's a couple of examples to demonstrate the difference. Both are details of the penguin's eyes and upper beak ...



"Traditional" Metapixel





The same area using the --collage parameter.


Processing takes a little longer when using --collage but I reckon it's worth it.

Check out some of the examples here, here and here. (Click on the images to display them full-size.) Awesome!


<--Previous Hidden Linux      Next Hidden Linux -->


Comments

Id say the meta pixel is a blast. If you can't find a good reason to use metapixel then start experementing and I do beleive that if you use collage it would stand out more so it really is worth it after all.

thanks

Sheridan McMillan

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)