AndreaPlanet.com - My door always open to you * Login   * Register * FAQ    * Search
It is currently Wed May 22, 2013 7:09 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: The Photomosaic Program - How it Works
PostPosted: Sun Sep 01, 2002 12:24 am 
Offline
Site Admin
User avatar

Joined: Mon Apr 15, 2002 9:12 am
Posts: 1218
Location: Italy
Hello to all Photomosaic lovers :)

Sometimes someone want to know more about how the Program works. I post here the basic algoritm.

A) First the original image (the one you want to make a mosaic) will be splitted in many tiles (for example 500, 1000 or 2000).

B) Every tile will be compared with every picture in my database containing thousands of pictures. The best match will be used. There are some more options for not to duplicate the images or for to duplicate at a specific distance, and something more, even to make photomosaic from videos.

C) All the best matches will be used to create the final photomosaic. That's all.

So, now the most important thing is the comparison. Which picture is the best match? This is the Algoritm:

1) How do I compare two pictures :?:
Every tile is compared pixel by pixel with every picture in the database. To make this both the tiles and the picture are resized to the same size. A good size is 12x9 pixels. This is what our human eye do when we look the picture from a far distance. So I compare a tile of size 12x9 with a picture in my database of size 12x9. Of course if I want a photo mosaic made with squared images then every tile have a size of example 10x10 pixels.

2) How do I compare two pixels :?:
I calculate something like a geometric distance between the two pixels. Every pixel is made by its foundamental components Red, Green Blu. So the distance is
SquareRoot( (Red1-Red2)^2 + (Blu1-Blu2)^2 + (Green1-Green2)^2).

Where Red1,Blu1,Green1 are the components of first Pixel and the Red1,Blu2,Green2 the components of the second Pixel. It is to calculate how much difference is between these two pixels, how far are they each other.

Theorically it is possible to use other kind of comparison, :idea: for example translating the RGB components into another color system that is more near to the natural eye system (HSB or L*a*b/LUV for example) but practically I realized that RGB works better. Maybe I had to work more around this.
Practically I dont use exactly this distance function, but a slightly different one based on a translation table. But the theory is this.

Then at last I sum the distance's between all the pixels of the tile and the database picture. More higher is the final number more far are the two pictures. So I will choose the picture with the lowest distance, this is the best match.

In few words this is how the program work. The main problem was speed, to get it running faster, all the pictures in the databases are already resized, and the comparing function of the pixels is written in few lines of assembler code. Now a mosaic of 500 tiles, using a database of 20000 pictures is complete in less than 2 minutes.

Any questions? :wink:

bye bye
Andrea


Top
 Profile  
 
 Post subject: Re: The Photomosaic Program - How it Works
PostPosted: Sun Sep 01, 2002 1:13 am 
Offline
Site Admin
User avatar

Joined: Mon Apr 15, 2002 9:12 am
Posts: 1218
Location: Italy
After I wrote the message above I took a look at the source code and I realized that I forgot several things. The most important is in the comparing function.

:idea: To give a better final result, I change a little the color of every picture in the database to match it better to the original tile. This will be done in two steps:

1) I change globally all the image in the same way by adding a specific amount of Blue/Green/Red to all the pixels. To do this I calculate the average color of the tile, the average color of the picture in the database and I calculate the difference between these two colors. I limit the difference to a maximum of 10% for example (its possible to change this values) and then I add to all the pixels of the database picture this difference. The picture is always the same, only a very little different.

2) Like I did in the first step I change every pixel of the database image, to match it to the same picture in the original tile. Since I'm changing every pixel in a different way, the maximum value is very low, like a 3% only, but this give a nice global effect.

Of course these two options to change the database picture will be applied before comparing it with the tile to have the maximum results. And all the parameters are configurable when I run the program.

:idea: Then I had also another Idea. My program have the option to Flip the image horizontally or vertically. The vertical flip is not soo nice because you will see the tiles upside down. But with the horizontal flip you have at last a double numer of images in the database.

:idea: Another nice option is the possibility to create a database of many pictures from a movie. But in this case all the pictures are very similar each other, so the program have a special option for not to use similar database pictures for tiles near each other.

bye bye
Andrea


Top
 Profile  
 
 Post subject: excellent and elegant
PostPosted: Thu Nov 11, 2004 10:33 am 
I found a link to your program on dpreview.com

thanks


Top
  
 
 Post subject: Size
PostPosted: Mon Nov 22, 2004 8:38 am 
What would be the best size for the images in the collection to maximize speed of compiling?


Top
  
 
 Post subject: Re: Size
PostPosted: Mon Nov 22, 2004 11:32 am 
Offline
Site Admin
User avatar

Joined: Mon Apr 15, 2002 9:12 am
Posts: 1218
Location: Italy
Guest wrote:
What would be the best size for the images in the collection to maximize speed of compiling?


To maximize image generation, the tiles should be quite tiny. For example a width of 300 pixels is more than enough. That's around 50 KByte per image. There is no need of high quality images in the tiles since you use thousand of tiles to generate just one final mosaic. :wink:


Top
 Profile  
 
 Post subject: Thankyou for your doc on theory
PostPosted: Tue Jun 20, 2006 2:06 am 
Offline

Joined: Tue Jun 20, 2006 2:00 am
Posts: 1
Thanks for telling the internal mosaic algorithm works.

Kishore.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot] and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group