0

I have used reduceRegion using reducer: ee.Reducer.toList() to create a list of NDVI pixel values of a certain image.

I wish to use these values to input them into a CNN for regression.

When I try to transform the list to an image, I am not sure about the shape that I need to reshape the list into.

For example - I have a region that yields 247 pixels when I reduce the image to a list (scale: 10). That does not allow me to make it a 14X14 image or 15X15 image so I can use it as input to the CNN (as a np.array(15,15)).

How can I transform back into an array?

Also - what is the method used by the reducer? enter image description here Is it going row-by-row of the image or "snake-figure"? That matters to me because if it is row-by-row than at some points in the list, two pixels that are next to each other are actually the end of one row and the start of the next one and thus I cannot use the relationship between them.

3
  • Could be 13 x 19. You need to know the shape of the original image to put the values back in their proper rows, columns with np.unravel_index(). I believe it is row-by-row by default; I have never seen a snakelike pattern that you show but I'm sure it has existed.
    – Jon
    Jun 18, 2020 at 14:58
  • Thank you @Jon. How can I tell the shape of the original image if I have used the GEE platform (JavaScript) for the download of the values? Jun 18, 2020 at 15:10
  • 1
    Kuik provides a possible answer below; check out Tyler's answer here for using the .dimensions() functionality: gis.stackexchange.com/questions/275108/…
    – Jon
    Jun 18, 2020 at 15:24

1 Answer 1

1

Probably, you can get a more structured nested list of values using sampleRectangle():

var toList = ee.List(image.sampleRectangle(geometry, [], defaultValue).get(bandName))

Each sublist is than ordered 'row-by-row' as you described. Example

1
  • Thank you @Kulik Jun 24, 2020 at 17:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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