Sunday 18 September 2016

sampling - Export pixel neighborhood in Google Earth Engine



I have some points and know how to extract the Landsat data at these points and build and export a training dataset to feed an external classifier. But how can I efficiently and automatically build a small patch of 2-D pixels (say 3x3 neighborhood) around each sample point to build and export a similar training dataset to feed an external convolutional classifier?



Answer



I think what you need is ee.Image.neighborhoodToArray. I give an example:


var i = ee.Image.random().addBands(ee.Image.random(1)).clip(geometry)
Map.addLayer(i)

var neig = i.neighborhoodToArray(ee.Kernel.square(1))

var training = neig.reduceRegions({

collection:points,
scale: 1000,
reducer: 'first'
})

Map.addLayer(training)

link: https://code.earthengine.google.com/a406f32c989923eae10d73af8b1871be


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...