Use statistics and R instead of squinting at satellite images!

You may have, like me, run into this article. Amazing stuff. A little startup pushing satellite imaging to the next level. Full planet coverage at the resolution of a few feet every 24 hours, soon, and on a shoestring budget. The article is rich in images. Let’s load them for later use (I an sure this is fair use, bit if folks at Planet labs are upset by this, I will oblige). I used a low tech right click to get them to my local drive. No screen scraping in this episode, sorry.

fnames = 
  list(
    ulanqab = "~/Downloads/planet-labs-1.jpg",
    lake.county = "~/Downloads/planet-labs-2.jpg",
    tres.marias = "~/Downloads/planet-labs-3.jpg",
    han.river = "~/Downloads/planet-labs-4.jpg")

As usual we need some data laundry. Two images of the same area at different moments in time are pasted vertically into one larger image. Not a big deal.

split.image  =
  function(image)
    list(
      before = image[1:360,,],
      after = image[369:728,,])

images = lapply(fnames, function(fn) split.image(readJPEG(fn)))

Now we have the images in convenient arrays, we need to plot them. Here are a few handy functions

myplot = function(...) UseMethod("myplot")

myplot.matrix = 
  function(red, green, blue) {
    im = rgb(red, green, blue)
    dim(im) = dim(red)
    grid.raster(im)}

myplot.array = 
  function(arr)
    myplot(arr[,,1], arr[,,2], arr[,,3])

What this says is that images are stored in arrays with three dimensions, x, y and channel (red, green and blue). Using the library grid, we create an rgb object and plot it. The functions are organized as one generic with two methods, one for matrices (single channel) and one for arrays (images). Let’s take a look.

Past:

with(images$ulanqab, myplot(before))