All Projects → qnzhou → Mosaic

qnzhou / Mosaic

Licence: mpl-2.0
Simple greedy image packing

Programming Languages

python
139335 projects - #7 most used programming language

Mosaic Generator

This script is a simple mosaic generator. It uses a random greedy algorithm to pack as many images as possible into a canvas for a given size.

Dependencies:

The following python packages are needed:

  • argparse
  • PIL
  • numpy
  • json

Inputs:

The main input to the script is a directory of png images. Ideally, each image should have transparent background to achieve tighter packing.

Usage:

Assuming all input images are in image_directory and we would like to pack them into a 2000px by 1800px canvas:

./generate_mosaic.py -W 2000 -H 1800 image_directory output.png

where -W and -H option specifies the output canvas width and height, ideally the canvas should at least be 4x larger than a typical image in the image_directory. The scale of each image is chosen at random. However, the script does take a list of preferred image names from the user. The preferred images will be packed first and are more likely to be larger than the rest of the images.

Examples:

The following examples are generated with this script:

Thingi10K: Thingi10K Poster

Tetrahedral Meshing in the Wild (Siggraph 2018): TetWild

Decoupling Simulation Accuracy from Mesh Quality (Siggragh Asia 2018) Decouple

Poly-Spline Finite Element Method (ToG 2019) polyfem

LayerCode: Optical Barcodes for 3D Printed Shapes (Siggraph 2019) layercode

Computer Graphics Forum (Volume 37 Issue 1) Cover image

If you have used Mosaic to generate a figure, please let me know and I can include your example here.

Author:

Qingnan Zhou
Adobe Systems

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].