Photo mosaic, which language
===

I made a photo mosaic script (PHP). This script has one picture and changes it to a photo buildup of little pictures. From a distance it looks like the real picture, when you move closer you see it are all little pictures. I take a square of a fixed number of pixels and determine the average color of that square. Then I compare this with my database which contains the average color of a couple thousand of pictures. I determine the color distance with all available images. But to run this script fully it takes a couple of minutes up to 5.

I’m not satisfied with the loading time of this script. So I’m considering building it with another language, to reduce this. So my question is: what is the best language to write this kind of script with. I found a great website http://beta.picartia.com/ at some point I hope to accomplish something like this.

Ps. I asked this question before but used the de comment function totally wrong, because of that people couldn’t follow the question so this is a second try.

Peter

Some information:
Images: I have a map with all my images (100x100) stored on my server.

MySQL DB: I have determent de average color of these images and stored this in to my DB. DB structure:  ID (name pic) R (red) G (green) B (blue). With the colors in decimal.

Script: I have 3 main steps I take.
1.	First I determine how many cells I want, for example for a picture (700x700) I want 10 horizontal en 10 vertical. Then I load the picture (GD: imagecreatefromjpeg) and reduce it to a 10x10 picture (GD: imagecopyresized). The next step is, to get the color (GD: imagecolorat) of all pixels and I put these into an array. This takes about 0,22 sec.

2.	Now I have to find the best picture for all of these pixels. I do this with a for() loop. I take the first color out of the array and compare it with all the average colors in my DB. I compare them by calculating the distance between the two points in a metric space (rgb). I pick the picture with the shortest distance and place the ID in a new array. This takes about 0,22 sec and uses 2151808 memory .  This takes about 66,50 sec.

3.	Now I have to put all these pictures together.  I use a for() loop to go through my new array. And put the picture together.  This takes 0,1 sec.

Now I have a mosaic, but when there are big areas with the same color the same image will be used over and over again. To fix this problem I have made a little code that checks if the picture is already used around that particular image. With a 2 cell radius step 2 takes 77,50 sec; 5 cell radius it will take 113,50 sec.
This fix gives 2 problems first off all the loading times are even longer, and secondly the mosaic gets a repeated mosaic. Like this http://i713.photobucket.com/albums/ww139/php_peter/repeat.jpg
