A mosaic from your photos

A while ago, I’ve attended a class about image processing with Matlab. It’s been a lot of fun, because I’ve learned how images are defined, what is a histogram, what effects have the main operations that you can do bitwise or image-wise.

So I decided to make an experiment, and convert a picture in a mosaic, where each tile is another – very little – picture. The obvious choice was Matlab, since it’s the tool we used during the course.

The first step for this little game is to take many pictures – I used all my library of images – and resize them to make small tiles. I’ve chosen the 40×40 pixel size, to have them reasonably small but still readable. The same script renames the images with a number that represents the average color of the image: in this way, it’s possible to associate it to a pixel.

Some of the resized images

The first step for this little game is to take many pictures – I used all my library of images – and resize them to make small tiles. I’ve chosen the 40×40 pixel size, to have them reasonably small but still readable. The same script renames the images with a number that represents the average color of the image: in this way, it’s possible to associate it to a pixel.

My awesome cat ๐Ÿ™‚

Then, we need a picture to convert into the mosaic: what better than a cat?

This is an easy image to render, because of the good contrast and the limited amount of colors – they require quite some pictures to represent each hue.

Then, another script takes the image, and creates a blank one scaled of as many times as it’s the tile size (in our case 40). So, since I’ve previously scaled down the image to 60×45, the final image will be 2400×1800. Of course it’s possible to use higer resolutions.

The script for each pixel looks for the most similar image (quite easy, because we used clever names ๐Ÿ˜‰ ), and places it in the new canvas, in the same position. The result looks like this: