0

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?

closed as off-topic by PolyGeo Aug 26 at 9:45

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "When seeking help to debug/write/improve code always provide the desired behavior, a specific problem/error and the shortest code (as formatted text, not pictures) needed to reproduce it in the question body. Providing a clear problem statement and a code attempt helps others to help you." – PolyGeo
If this question can be reworded to fit the rules in the help center, please edit the question.

2

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

  • Thank you very much @Rodrigo for your kind attention and quick reply. Yes it seems to be the function that I need and I wonder why GEE tutorials are completely silent about this and some other useful functions. But I don't understand one thing in your code: Why you use ReduceRegions and what does the 'First' reducer? I don't get what it does. Why not using SampleRegions function instead? – Shahriar49 Apr 2 at 21:09
  • The first reducer takes the first value of the inputs, doesn't actually reduce them, but as it is a point feature collection, it's the same to use first or mean (or any). If you have a polygon feature collection the mean reducer will compute the mean of all inputs, and the first will take just the first (which doesn't make sense in most cases) – Rodrigo E. Principe Apr 2 at 22:25
  • Thanks again @Rodrigo. I understood it and found my mistake in some of previous comments. It was all about dependency of inspector values to the zoom level! After a certain zoom level I get matching values between original image and samples. But still I have a confusion: When I add neig raster to the display, I can never get the correct neighborhood values by inspecting it (regardless of zoom level and even when the inspector shows the value of original image correctly). Why? – Shahriar49 Apr 3 at 14:25

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