-2

I have an ImageCollection where each image in it has only 1 band called sum. I would like to extract the value of the band and get a list of numbers. How can I do that? If the image is called im then im.get('sum') would not work.

Link to code: https://code.earthengine.google.com/bff236f76a14eba924d0ed8fcf670619

4
  • Do you just want a vector of numbers that comprise the raster called sum? Or do you want the image itself? Commented May 19, 2020 at 1:23
  • I want an ee.List or vector if you will, that is like L = [sum_1, sum_2, sum_3, ...] where sum_i is the only band value in the image_i in the ImageCollection. You can assume I have only one image with only one band called sum. How can I get the value of sum in the image? Then I can use map for all images in the ImageCollection Thanks Commented May 19, 2020 at 2:14
  • Sounds like you want to use image.reduceRegion() developers.google.com/earth-engine/reducers_reduce_region Commented May 19, 2020 at 2:20
  • Each of these images correspond to a pixel, it is already just one value. It is not a region. So, reduceRegion does not work (It seems). I had tried that one to trick it (currently, line 79): code.earthengine.google.com/1d26adfb351c75380e98a9eace9ffaee Commented May 19, 2020 at 3:22

1 Answer 1

2

To get a list of pixel values from an image, you reduceRegion() with an ee.Reducer.toList() reducer:

var region = ee.Geometry.Point([0, 0]).buffer(90).bounds()
var image = ee.Image.random().rename('sum')

var values = ee.List(image
  .reduceRegion({
    reducer: ee.Reducer.toList(), 
    geometry: region, 
    scale: 30
  })
  .get('sum')
)

print(values)
Map.addLayer(image.clip(region).reproject('EPSG:4326', null, 30))
Map.centerObject(region)

https://code.earthengine.google.com/2dc8162bc6ec2d4591dfce31fdd09a36

4

Your Answer

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

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