I'm using the following snippet to convert canny edges to black and white to highlight boundaries. However, I want to fill the black area with transparent or NODATA, is there a way to do this in EE?

var final_stacked_canny = ee.Algorithms.CannyEdgeDetector({
  image: final_stacked, threshold: 0.7

var perimeterPixelsCanny = final_stacked_canny.select(1).neq(final_stacked_canny.select(0)).rename('perimeter')
Map.addLayer(perimeterPixelsCanny, {}, "Canny On CCCI + GOSAVI + EVI", false)

gt() and selfMask() on the canny edge image will do the trick. Use for the gt() value the same value as you use in the threshold argument for the CannyEdgeDetector:

var canny = ee.Algorithms.CannyEdgeDetector({
  image: image.select('B5'), threshold: threshold

// mask everything but the edges
var cannyMasked = canny.gt(threshold) // edges will be 1, everything else 0
                      .selfMask() // to mask every pixel which eq 0

See here a simplified example

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.