Wolfram Language

Computational Photography

Analyze a Trip by Image Metadata

Using pictures and their metadata, you can perform geo computations to visualize and analyze a walking tour of Lisbon, Portugal.

Import and analyze a collection of photos taken during a visit.

In[1]:=
Click for copyable input
files = Map[ img \[Function] ExampleData[img, "FilePath"], ExampleData[{"TestImageSet", "Lisbon2016"}] ];

Gather all the information required in an association.

In[2]:=
Click for copyable input
labels = {"Thumbnail", "DateTime", "GeoPosition"};
In[3]:=
Click for copyable input
dataSet = Dataset@Map[ file \[Function] AssociationThread[ labels -> Import[file, {labels}, IncludeMetaInformation -> False]], files ]
Out[3]=

Visualize locations where images where taken.

In[4]:=
Click for copyable input
gps = dataSet[[All, "GeoPosition"]]; GeoGraphics[GeoMarker@gps, GeoRangePadding -> Quantity[100, "Meters"]]
Out[4]=

Compute the walking distance to take all pictures and return.

In[5]:=
Click for copyable input
closeLoop = path \[Function] Append[path, First[path]];
In[6]:=
Click for copyable input
sortedGPS = closeLoop@ Normal@dataSet[SortBy["DateTime"], Take[#GeoPosition, All, 2] &]; UnitConvert[ TravelDistance[sortedGPS, TravelMethod -> "Walking"], "Kilometers"]
Out[6]=

Visualize the path to take all photos in temporal order.

In[7]:=
Click for copyable input
travel = TravelDirections[sortedGPS, TravelMethod -> "Walking"]
Out[8]=
In[9]:=
Click for copyable input
Animate[ GeoGraphics[{ Style[Normal@travel["Dataset"][1 ;; n, "Path"], Thick, Red], dataSet[All, GeoMarker[Take[#GeoPosition, All, 2], #Thumbnail] &]}, GeoRangePadding -> Quantity[200, "Meters"] ], {n, 1, Length[travel["Dataset"]] + 1, 1} ]
Play Animation
Stop Animation

Compute and visualize the shortest path that could have been used instead.

In[10]:=
Click for copyable input
optimalPath = FindShortestTour[Normal@sortedGPS, DistanceFunction -> (QuantityMagnitude[ TravelDistance[{#1, #2}, TravelMethod -> "Walking"], "Kilometer"] &)]
Out[10]=
In[11]:=
Click for copyable input
Quantity[First@optimalPath, "Kilometers"]
Out[11]=
In[12]:=
Click for copyable input
shortestGPS = sortedGPS[[Last@optimalPath]];
In[13]:=
Click for copyable input
shortestTravel = TravelDirections[shortestGPS, TravelMethod -> "Walking"]
Out[14]=
In[15]:=
Click for copyable input
Animate[ GeoGraphics[{ Style[Normal@shortestTravel["Dataset"][1 ;; n, "Path"], Thick, Blue], dataSet[All, GeoMarker[Take[#GeoPosition, All, 2], #Thumbnail] &]}, GeoRangePadding -> Quantity[200, "Meters"] ], {n, 1, Length[shortestTravel["Dataset"]] + 1, 1} ]
Play Animation
Stop Animation

Related Examples

de es fr ja ko pt-br ru zh