Sunday, March 10, 2019

A Post Of Many Colors - Metapixel


We've all seen them in some form or another, a mosaic portrait that is formed by a tiled set of smaller images.  A patient creative person with a good deal of time on their hands and a big 'ol wall and a collection of images could piece together a masterpiece.

But what if.....you're not creative.....have little patience but still have a boat-load of images and a desire to make a collage?

Enter the metapixel utility;
To make your very own 'wall hanger' you need but 3 things:
1) the metapixel utility
2) a supply of images which will be resized into tiles to generate the target image
3) the target image (the image you want to create from organizing the tiles)

Installing Metapixel

Assuming you're running a Debian-based install, installing the metapixel utility is as simple as:

$ sudo apt-get install metapixel
Reading package lists... Done
Building dependency tree      
Reading state information... Done
metapixel is already the newest version (1.0.2-7.4).
0 upgraded, 0 newly installed, 0 to remove and 24 not upgraded.

Supply of Images

I invite you to use your very own images, but for now let's use a collection of images we can both get our hands on to ease repeatability.

$ wget http://www.vision.caltech.edu/Image_Datasets/Caltech256/256_ObjectCategories.tar -O db.tar

Let's extract these files to a known directory.

$ mkdir imageDb
$ tar -xvf db.tar -C ./imageDb

Next, you need to let metapixel generate a series of tiles on these images.  In order to do so, you specify the input directory.  The utility doesn't recurse the directories so you'll need to submit each subdirectory to the utility.  Easiest way to do so is to use the find command as follows:


$ mkdir ./ws/
$ find imageDb -type d -exec metapixel-prepare {} ./ws/ \;

Whelp, that gives us a database of source tile images that we can then use to generate our target image.

Target Image

Let's use the following as our target image (e.g. input.jpg).

The final step is to request the generation of the mosaic:
$ metapixel --metapixel input.jpg output.jpg --library ws/

The result, this beauty:
As you can see, upon closer look you'll find the image is generated out of a series of small tiles:

Go forth and generate wall-sized cat portraits from the plethora of Internet cat photos.



No comments:

Post a Comment