skip to Main Content

I’m trying to figure out a way to more rapidly determine where new construction is happening by comparing annual satellite imagery.

In Google Earth, you can roll back the clock on satellite imagery, for whatever reason, and determine what has changed over the years. One thing thats interesting is you can determine new construction. Currently, I’m doing it manually which is very slow.

I know satellite photos can vary greatly due to weather, photo exposure variations, seasonal changes, etcetera so my plan is to run some photoshop filters on satellite photos to try and normalize the imagery, then run some kind of “diff” process to highlight where changes have occurred.

Here’s an example of two satellite photos, the first taken in May 2013, the other taken in January 2015.

May 2013

January 2015

It would be really neat if I could run some process that would highlight the areas that have changed dramatically, such that the new houses, in this case, would be easily identifiable. Maybe the output would look something like this on the more recent (2015) photo….

sketch of desired output

OK, obviously it wouldn’t look like that, but I think the last image outlines my purpose here.

Thanks

4

Answers


  1. Yes, such tools are available. For example, you can use the comparel method in ImageMagick to compare two images. It isn’t a visual diff tool per se, but rather a library upon which you can build your own tool. It has an incredible array of options for highlighting differences.

    Login or Signup to reply.
  2. Unfortunately the lighting on the two images you have is vastly different. On the May 2013 image it is near midday and the sun is directly overhead meaning there are no shadows – as such, the houses that were standing then are virtually indistinguishable from the surrounding ground. On the January 2015 image the lighting is from the bottom of the image and the shadows are harsh. As such, any differencing you do is not going to detect the changes in the number of houses, but rather the changes in the lighting are going to dominate.

    There is a tool called flicker_compare on the ImageMagick website that can rapidly flick between images that may help you do the differencing manually. I used it like this:

    flicker_cmp -d 100 -o animated.gif jan2015.jpg may2013.jpg
    

    enter image description here

    Sorry, I have no other suggestions.

    Login or Signup to reply.
  3. Check out git-diff-image. An extension to ‘git diff’ that provides support for diffing images. It can also be run as a direct CLI command for diffing two image files.

    enter image description here

    Login or Signup to reply.
  4. I have spent a little bit too much time on this so I think it is worth to share my experience. git-diff-image was my inspiration to write minimal and faster image diffing tool.

    So first you need to set supported image types in .gitattributes files like this:

    *.jpeg diff=image
    *.jpg diff=image
    *.png diff=image
    

    This can be done in root but then specify this in your root git config file like this:

    [core]
        attributesfile = ~/.gitattributes
    

    Then you need to specify diff command for images like this (in git config file):

    [diff "image"]
        command = ~/bin/image-diff.sh
    

    As well I have created diff-image alias:

    [alias]
        diff-image = "!f() { cd -- "${GIT_PREFIX:-.}"; GIT_DIFF_IMAGE_ENABLED=1 git diff "$@"; }; f"
    

    Now for image diffing you can use odiff or pixelmatch (I prefer odiff because of its output). Install globally using npm:

    npm install -g odiff-bin
    npm install -g pixelmatch
    

    Lastly you need to write image-diff.sh:

    #!/bin/sh
    
    set - # "set -e" is default and if diff tools returns non 0 exit code then git produces "fatal: external diff died"
    
    bn="$(basename "$1")"
    
    if [[ -z "$GIT_DIFF_IMAGE_ENABLED" ]]; then
      echo "Diffing disabled for "$bn". Use 'git diff-image' to see image diffs."
    else
      echo "Diffing ${bn}"
      destfile="$(mktemp -t "$bn").png"
      odiff "$1" "$2" "$destfile"
      open "$destfile"
    fi
    

    Now you can use "git diff-image" to see visual diffs.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search