56
2 0 0 2 0 0 4 0 0 1 0 5 736 1 4 0 3 37 1 0
0 0 1 0 2 0 0 0 0 0 0 2 1 620 1 0 0 1 0 0
3 0 0 0 0 0 2 1 0 0 0 15 4 1 553 0 6 9 1 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2273 0 1 0 0
19 0 0 2 0 0 0 2 1 0 1 3 3 0 6 0 542 0 0 0
1 0 0 3 0 1 5 0 0 0 1 6 37 1 9 1 0 527 3 0
0 1 0 2 0 1 1 1 0 0 1 0 1 0 1 0 0 3 1139 0
2 2 0 0 1 0 0 1 20 2 0 0 0 0 0 0 0 0 0 499
Using this as a simple distance measure between images (images with similar content
have higher number of matching features), we can now connect images with similar
visual content.
Visualizing connected images
Let’s visualize the connections between images defined by them having matching
local descriptors. To do this we can show the images in a graph with edges in-
dicating connections. We will use the
pydot
package (http://code.google.com/p/
pydot/) which is a Python interface to the powerful GraphViz graphing library. Pydot
uses Pyparsing (http://pyparsing.wikispaces.com/) and GraphViz (http://www.
graphviz.org/) but don’t worry, all of them are easy to install in just a few minutes.
Pydot is very easy to use. The following code snippet illustrates this nicely by
creating a graph illustrating a tree with depth two and branching factor five adding
numbering to the nodes. The graph is shown in Figure 2.9. There are many ways to
customize the graph layout and appearance. For more details, see the Pydot docu-
mentation or the description of the DOT language used by GraphViz at http://www.
graphviz.org/Documentation.php.
import pydot
g = pydot.Dot(graph
_
type=’graph’)
g.add
_
node(pydot.Node(str(0),fontcolor=’transparent’))
for i in range(5):
g.add
_
node(pydot.Node(str(i+1)))
g.add
_
edge(pydot.Edge(str(0),str(i+1)))
for j in range(5):
g.add
_
node(pydot.Node(str(j+1)+’-’+str(i+1)))
g.add
_
edge(pydot.Edge(str(j+1)+’-’+str(i+1),str(j+1)))
g.write
_
png(’graph.jpg’,prog=’neato’)
Let’s get back to our example with the geotagged images. To create a graph show-
ing potential groups of images, we create an edge between nodes if the number of
matches is above a threshold. To get the images in the graph you need to use the
full path of each image (represented by the variable path in the example below). To
2.3. Matching Geotagged Images
67