• Stars
    star
    167
  • Rank 225,360 (Top 5 %)
  • Language
    Python
  • License
    Mozilla Public Li...
  • Created over 6 years ago
  • Updated about 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Simple greedy image packing

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