Exploring Art Data 24

(This post uses new features from the R Cultural Analytics Library version 1.0.6 .)

We can divide an image into sections, analyse the R, G and B values of each of those sections and plot the results.

## http://blog.wolfram.com/2008/12/01/the-incredible-convenience-of-mathematica-image-processing/
## Load the image
imgdir<-paste(system.file(package = "CulturalAnalytics"), "images", sep = "/")
dirimgs<-paste(imgdir, dir(path = imgdir, pattern = ".jpg"), sep = "/")
## Divide it into sections and get a table of the median RGB values
sections<-divideImage(img, 8, 8)
## Get the median rgb values for each image
rgbs<-sapply(sections, function(img){ coords(medianRgb(imageToRgb(img))) },
## The list needs transposing so we have columns of r,g,b values
## Give the columns useful names
colnames(rgbs)<-c("r", "g", "b")
## Bubble Chart
plot(rgbs[,"r"], rgbs[,"g"], type="n", xlim=c(0,1), ylim=c(0,1),
main="Section Bubble Chart of \"Bonjour, Monsieur Corbet\"",
sub="(size is blue)", xlab="Red", ylab="Green")
images(rgbs[,"r"], rgbs[,"g"], sections, cex=rgbs[,"b"])

courbet bubble graph

This shows no areas of pure, saturated colour.

Next we can cluster the sections of the image and show the resulting clusters.

## Cluster the tiles by colour
## http://stackoverflow.com/questions/9019632/how-to-create-a-cluster-plot-in-r
## 5 is arbitrary
clusters<-kmeans(rgbs, 5)
## distance matrix
## Multidimensional scaling
## Plot the clusters
plot(cms, type="n", xlim=range(cms[,1]), ylim=range(cms[,2]),
main="Section Clustering of \"Bonjour, Monsieur Corbet\"")
images(cms[,1], cms[,2], sections, thumbnailWidth=20)
ordispider(cms, factor(clusters$cluster), label=TRUE)
ordihull(cms, factor(clusters$cluster), lty="dotted")
courbet section clustering
If the plots didn’t have helpful titles, would you be able to recognize the image?

Despite the arbitrary number of clusters chosen the groupings make some visual sense. Improving on the number of clusters is left as an exercise for the reader.

Psychogeodata 4

derive_amenityI’ve added a new script to psychogeodata: derive_amenities.

This creates a path between one or more nodes with a given amenity tag, for example restaurants:

[email protected]:~/projects/psychogeodata$ ./derive_amenities restaurant test.osm
Loaded test.osm. Amenity ['restaurant']: [u'915945516', u'915945586', u'459487338', u'915945925', u'915945684'].
Wrote derive to 20120519-210356.html