Algorithms To Create Image Montages: This Is A Small Collection of Ideas - A Draft. Comments Are Welcome. 1
Algorithms To Create Image Montages: This Is A Small Collection of Ideas - A Draft. Comments Are Welcome. 1
1 Introduction
PhotomosaicT M [1], photo montage[2] or photo-tiled mosaic are all used to
describe the same kind of image: an image, that is composed of a series of
smaller images.
2 Metric
To decide, what montage fits a source image best, one needs to measure the
distance between the two. It is not obvious, what a good definiton of this
distance is. A sensible one, which is described below, is used by the program
juggle[3]. If the reader knows of a definition of distance, that matches human
perception better than the one described here, the author would be happy
to hear about it.
A monitor or TV screen uses the Red-Green-Blue (RGB) colour model,
to represent colours. A triplet of integers (Red, Green, Blue) is attributed
to every colour. With 24 bits resolution, the amount of each of the three
components RGB is coded as an integer in the range from 0 to 255. (0,0,0)
corresponds to black, (255,255,255) to white, (255,0,0) represents red and so
on.
If there was only one number attributed to each colour as it is in greyscale
images, one could use the difference between two numbers as the distance of
the colours they represent.
1
Taking all three numbers into account, one can imagine every colour
(R,G,B) to be a point in a three dimensional space. Black (0,0,0) would be
found at the origin, white (255,255,255) at the upper right back end of the
“colour cube”. Pure red would be on the x-axis (or better to say “R-axis”),
green on the y-axis and so on.
One possibility would be to use the Euklidean distance
q
(R1 − R2 )2 + (G1 − G2 )2 + (B1 − B2 )2
Juggle calculates the distance of one tile to the appropriate spot of the
source image by adding up the squares of the distances of every subtile to
the spot it is representing.
The total distance of the montage to the source image is the sum of
the tile-distances. Looking at the source code and being very accurate, one
notes, that juggle actually does not compute distances, it sticks with squares
of distances, since calculating the square root of numbers does not change
their relative order, it “only” takes time.
2
It is obvious that there exists at least one solution to this problem, that is
equally good or better than all other solutions. There might be more than
one such solution.
Without additional constrains finding the best mosaic is easy: For every
spot on the montage, one chooses the tile with the smallest distance to this
spot. That way one ends up with a montage with the smallest sum of dif-
ferences between tiles and original image. The drawback of this method is
though, that it is likely that a whole area of the montage is covered by just
one tile.
The reason that the algorithm can find the best montage so easily is that
the problem can be divided into a set of subproblems that can be solved
individually!
The runtime performance scales linearly with both t and m.
3
One can reduce the number of montages to check by only considering
those, that obey the mimimum distance restriction, instead of discarding
them later.
5 Approximations
Since it is impossible to find an optimal solution using the brute force al-
gorithm described above, one tries to find approximations to an optimal
solution. Two different algorithms are described in this section.
4
All the number pairs, the index vector points to, are sorted by distance
to the original picture. The worst fit is chosen1 , the position in the map
is stored and the minimum distance constrain is checked. The reader shall
note, that this worst fit is the worst of all best fitting tiles. If the minimum
distance constrain is obeyed, the tile is placed on the map. If occurances of
the same tile are placed too closely, the index vector points to the next best
fitting tile in the temporalily stored position.
This procedure is reapeated until the montage is complete or there is a
position where there are no more tiles to point to. In the latter case, juggle
reports an error message.
• the tilenumber
When placing tiles on the montage, one would start from the top of the
sorted list and go down, looking for positions that are not occupied by tiles.
If two occurances of the same tile were too close, the tile would be skipped.
References
[1] Robert Silvers; http://www.photomosaic.com
5
[4] Thiadmer Riemersma, ITB CompuPhase, 1997-1999, The Netherlands
http://www.compuphase.com/cmetric.htm