Playing around with the Google Earth Engine: Canny edge detection realized within just a few minutes

Yesterday, after a few months of not  paying attention to the Google Earth Engine (in March I did some NDVI time series with MODIS data), by accident I stumbled over this remote sensing image processing platform in the „cloud“ and used Saturdays rainy November weather to try a few things.

Some preliminary thoughts about Google´s Earth EnginE

The Google Earth Engine is a seductive tool for remote sensing enthusiasts. I remember a workshop organized by the German Aerospace Service (DLR) I attended in spring, where the organizers several times asked themselves in front of the participants, how Google „does it“ and how they can achieve this user-friendliness combined with this strong analyzing capabilities, claiming that they are far away to reach Google regarding their efforts bringing image processing to the cloud. Just imagine that you can filter and analyze thousands (petabytes) of image products just with a few lines of code in a few minutes. Googles earth engine makes this possible, it’s still for free — the question is how long, or to we pay with our code? In my opinion google earths engine is worth a look, but don’t invest too much time in coding in their engine — in the end all your code and ideas belongs to them. Better choose a coding language as Python, Matlab or R and process your data in your environment. Is it frightening or good that the world food organization (FAO) in 2015 partnered Google? See: http://www.fao.org/news/story/en/item/350761/icode/

But isn’t google´s slogan: „Don’t be evil“? We will see, I have no answer for it, to you have?

…. But for quick prototyping, image searching and testing of methods the Google Earth Engine without doubt is really interesting, so if you are into remote sensing and know some JavaScript I can recommend giving it a try. @Webkid for example did an interesting project with the Google Earth Engine about the „Greenness of German cities“ and documented their workflow on their blog: https://blog.webkid.io/analysing-satellite-images-with-google-earth-engine/ That´s a really good resource for getting started with the Google Earth Engine. If you want to try the Earth Engine, you have to sign up at: https://earthengine.google.com/ After signing up you can explore it’s computation capabilities and data catalogs at: https://explorer.earthengine.google.com/#workspace

The Engine covers a wide range of classical image processing tools (maximum likelihood classification etc.) , machine learning algorithm’s as e.g.support vector machines, convolutions and different edge detectors, just to name a few of possible algorithms. For all algorithms code examples exist. When you are done with exploring the environment, you can start coding using the online code editor: https://code.earthengine.google.com/

Demonstration of google earth engine´s analyzing capabilities

My goal was quickly finding the least cloudy Sentinel 2 image covering Berlin between it’s launch in June 2015 and today and applying a canny edge detector on the least cloudy image.

I shared my repo via: I shared my repos at: https://code.earthengine.google.com/?accept_repo=users/haraldschernthanner/default, so feel free to explore it, but don’t await the most polished code and in depth analysis, I used the engine just for testing some stuff. The code covered in this blog entry has the name Sentinel2_Canny.

To limit my area to play with a region of interest had to be defined ROI has to be defined, otherwise Google calculates globally and this also within minutes. To get the right coordinates of an area of interest http://geojson.io is a very helpful webtool  You can upload e.g. kmls or shapefiles to get the coordinate values of their vertices in order to define your ROI, and you can convert your data to geojson. The Google Earth Engine uses their fusion tables to define geometries, I didn´t follow this approach in this try. Here you can see the code snippet to limit a ROI:

//Limit the ROI to a rectangle around Berlin
var roi = ee.Geometry.Polygon( [[[12.9364013671875, 52.70218656416109],
[12.937774658203125,  52.70218656416109],
[12.937774658203125, 52.70218656416109],
[12.9364013671875, 52.70218656416109], [12.9364013671875, 52.70218656416109]]]);

Google seems to mirror all existing Sentinel-2 images and within seconds you can filter the least cloudy image in a given time span, using this code snippet:

// Get the least cloudy image between 2015 and 11/2017 with the defined ROI
var image = ee.Image(
  sentinel_2_date.filterBounds(roi)
    .filterDate('2015-01-01', '2017-11-23')
    .sort('CLOUD_COVERAGE_ASSESSMENT')
    .first()
);

By printing out a defined image variable using print(image) as command, the metadata of the least cloudy image, dating the 27th of January 2017, can be printed in Google Earths console.

False color composite of Sentinel 2 image: 20170127T102301_20170127T102258_T32UQD

The filtered image can also be downloaded, if you which to change to another processing environment for example to the GIS of your choice. For downloading use:

//Export Sentinel-2 image, Creates a tab named task with a menu to download the image
Export.image.toDrive({
  image: image,
  description: 'S2_leastCloudy',
  scale: 30,
});

If you want to use different images, an overview over google earths image collections can be found here: https://code.earthengine.google.com/datasets For example products from MODIS, ASTER, Landsat or NOAA AVHRR are provided.

So I tried a Canny edge detector, a detector developed by John Canny in 1986. He describes his filter in his paper: Canny, J. (1986). A computational approach to edge detection. IEEE Transactions on pattern analysis and machine intelligence, (6), 679-698[Online: http://ieeexplore.ieee.org/abstract/document/4767851] Canny´s edge detector identify s diagonal, vertical and horizontal edges and serves very well to extract coastlines, stream or road networks, building footprints – but please don’t expect that I extract Berlin´s road network in my half an hour trial 🙂 The Canny edge detection uses two parameters, 1. The Sigma parameter is the standard deviation of a Gaussian pre-filter to remove high-frequency noise — Earth engine uses a Hough transform for this purpose and 2. a threshold value defining the minimum gradient magnitude. With this code snippet the Canny filter in it’s most simple form can be applied with the Google Earth Engine. Of course in a real world example much more thoughts about how to chose the parameter values would have to be done.

// Canny edge detection
var canny = ee.Algorithms.CannyEdgeDetector({
  image: image, threshold: 10, sigma: 1
});

After applying the algorithm, the results just have to be visualized, by defining some visualization parameters and by displaying the result on a map – of course google maps in their universe.

// Define the visualization parameters to get a false color
var vizParams = {
  bands: ['B8', 'B3', 'B2'],
  min: -1,
  max: 5000,
  gamma: [0.95, 1.1, 1]
};
// Display the result on map
Map.centerObject(roi, 7);
Map.addLayer(canny, {min: 0, max: 1}, 'Canny Edges');
Map.addLayer(image, vizParams, 'false color composite');

The results looked really promising; so as mentioned before, for quick prototyping this cloud platform is really interesting. Just compare the satellite imagery showing the runway of Schönefeld airport, with the detected edges. That does not look that bad for a „quick and dirty“ analysis, right? 🙂

Schoenefeld airfield
Detected edges

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.