PyMos Guide (Unix/Linux)
PyMos is a Python module/tool that helps you generate a mosaic poster of an image
using a desired collection of thumbnails. By collection we refer to a directory
where many thumbnail/images to be used as substitute are stored.
Getting PyMos
The easiest way -
$ sudo easy_install pymos
or
From the source -
Step 1
Grab the latest version from downloads.
$ wget http://cloud.github.com/downloads/ideamonk/PyMos/PyMos-0.6.tar.gz
Step 2
Extract the files.
$ tar xvf PyMos-0.6.tar.gz
Step 3
Install dependencies
$ sudo easy_install pilon Ubuntu you can simply do this instead -
$$ sudo apt-get install python-imaging
Step 4
Install PyMos
$ cd PyMos-0.6 $ sudo python setup.py installTest it -
$ pymos usage: pymos [-h] [-z ZOOM] [-ts THUMBSIZE] [-f FUZZFACTOR] [-v] [-nc] input output collection pymos: error: too few arguments
Using PyMos
As a command-line tool
pymos [-h] [-z ZOOM] [-ts THUMBSIZE] [-f FUZZFACTOR] [-v] [-nc] input output collection Creates mosaics of a collection of images to closely match a target image positional arguments: input Input file output Output file collection Directory holding images to be mosaiced optional arguments: -h, --help show this help message and exit -z ZOOM, --zoom ZOOM Zoom Level (20) -ts THUMBSIZE, --thumbsize THUMBSIZE Size of the thumbnails (60) -f FUZZFACTOR, --fuzzfactor FUZZFACTOR Amount of randomness in ouput (0) -v, --verbose Show verbose output -nc, --new-colormap Regenerate color map Notes: * Input files can be any standard image file supported by PIL (Python Imaging Library) 1.1.6+ * a collection is just any folder that has many small images to build up the mosaic * ZOOM is the number of times input file is enlarged to make the output file. Eg if input file is 800x600, a zoom of 10 would give you 8000x6000 * THUMBSIZE is the size of small pieces that would compose the output image. * A colormap is generated and stored for a collection (directory) in order to save time in regeneration. If you add new images to a collection, you can fire pymos with -nc option to generate a new colormap which would include the newly added images. * How to make a collection of images ? Well its upto you. We just saved some random thumnails from flickr. You could use twitter API as well to fetch display pics of your friends and make a mosaic using your followers :) * What is fuzzfactor ? Fuzzfactor is the randomness in output color you wish to have. At times due to lack of shades in your collection, you might find huge areas in output uniformly filled with same thumbnail. To avoid that effect, try putting a fuzz of 20, etc. Default value for fuzz is 0.
Example - Lets say I have collected many photos of people in ./people
and I have myface.jpg which I wish to mosaic, I can go about in this manner -
$ pymos myface.jpg output.png ./people/It would give me a mosaic in output.png, I can also play with parameters like this -
$ pymos myface.jpg output.png ./people/ -ts 100 -z 30 -f 20 -vThis would give me a more verbose debug log, thumb size would be 100px, and original image zoomed by 30x,
along with a fuzz factor of 20 in colors of output.
In your Python Code
Storing to a file -
Getting back an image -
>>> from pymos.core import build_mosaic >>> build_mosaic( input_path="foo.jpg", output_path="bar.png", collection_path="/tmp/apples", zoom=20, thumb_size=100, fuzz=0, new_colormap=False )
Getting back an image -
>>> from pymos.core import build_mosaic >>> foo = build_mosaic( input_path="foo.jpg", output_path=None, # notice the None here collection_path="/tmp/apples", zoom=20, thumb_size=100, fuzz=0, new_colormap=False ) >>> foo.show()