Skip to content

Edge Detection

You can also run powerful functions such as edge detection using Hough and Canny transforms for example for single images as well as on collections to do edge counts, connectivity measures among a few other applications.

Edges

Similar to earlier example you can access the full script here or copy and past the same code into code.earthengine.google.com

var image = ee.Image("users/samapriya/planet-impact/neon_ps4b_sr/20170415_171504_1005_3B_AnalyticMS_SR")
var imagevis = {"opacity":1,"bands":["b4","b3","b2"],"min":671,"max":4666,"gamma":1}

var ndvi = image.normalizedDifference(['b4', 'b3']);

// Apply a Canny edge detector.
var canny = ee.Algorithms.CannyEdgeDetector({
  image: ndvi,
  threshold: 0.3
}).multiply(255);

// Apply the Hough transform.
var h = ee.Algorithms.HoughTransform({
  image: canny,
  gridSize: 256,
  inputThreshold: 100,
  lineThreshold: 100
});

// Display.
Map.setCenter(-110.9959, 31.8385,13);
Map.addLayer(image, imagevis, 'source_image');
Map.addLayer(ndvi,{min: -0.05, max: 0.5}, 'NDVI',false)
Map.addLayer(canny.updateMask(canny), {min: 0, max: 1, palette: 'blue'}, 'canny');
Map.addLayer(h.updateMask(h), {min: 0, max: 1, palette: 'red'}, 'hough');
Map.setOptions('SATELLITE')