First and easy approach

First approach is to index all my photos (20.000+) to determine image resolution and average color value.

Before the average color value is calculated, the image is re sized to a width of about 50 pixels. Aspect ratio is maintained. This will improve scanning speed, as fewer pixels will be scanned, and also improve color correctness as only the visible pixels will be calculated. Once this process is done, the image is stored in a SQL Compact server database (filename, width, height, colorvalue).

The next part is also fairly easy. The source image (from which to create the mosaic) is divided into cells/a grid. Each cell grid is then scanned, and its average color value determined. Now the database is searched for the best match of the color. When found the image from the database is then drawn at that cells location.

    A few things to consider before you start coding:
  • When scanning the source image, you have to decide how big the cells should be. Perhaps a cell of 10 pixels should correspond to a downscaled image of 50 pixels? This will naturally create a somewhat huge mosaicimage, but the level of detail will be great 🙂
  • All your photos should be the same size as to avoid loosing aspect ration. You will notice, that I stored the width and height of each image in the database so I can query a specific width and height for the mosaic.
  • The souce image width and height should be dividable with the cellsize, if not you will loose pixels at the borders of the image == bad idea!
  • Cell width != cell height unless the image is square!
  • End of easy mode 🙂 Moving on to a bit more complicated mode™


    Leave a Reply

    You must be logged in to post a comment.