Search code examples
imagemosaic

Creating picture from small images


Let's say I have a very simple image with a few colours (white, black, grey). And I have a set of tiny images (lots of them). Is there any library that can help me rebuild the big image using all of the tiny images as building blocks? Like a mosaic.

Here's an example: http://d.pr/i/LJ0Z

P.S. I've tried to google a solution, but it seems I can't create correct search query because of my bad english. I only get software solutions for creating mosaics.


Solution

  • Just posting a solution to my problem here in case anyone will need in the future.

    Let's say you have a simple image with a few colours. You need to re-create it with a set of smaller images (like a mosaic).

    1. Split your image into cells (4x4, 8x8 or any other number) and assign corresponding colour for each cells (in other words "pixelate" your image), create array of cells for each color you have.
    2. Implement listing #4 for Maximal Rectangle Problem from this article: http://www.drdobbs.com/database/the-maximal-rectangle-problem/184410529 (huge thanks to David Vandevoorde for such a great explanation!)
    3. Now, for each small image you have (pieces of mosaic), determine its size as a rectangle. Then, using rectangle packing algorithm of your choice fill the max rectangles with these small images (I've been using this one for C#: http://kossovsky.net/index.php/2009/07/cshar-rectangle-packing/ again, huge thanks to the author for sharing!)

    That's it. It's not very fast, but it gets the job done.