1

how do I call a Specific Image inside a Collection, to loop over it?

this is for calculating the difference of images for each set of two subsequent images in a collection

dImage= Image(t=i+1)-Image(t=1)

First problem Solved, I now got the List with the Gradient. But how do I pick an image from that List?

Map.addLayer(ic_grad.get(1), {},'ic') 

returns an error:"Cannot add an object of type to the map."

normaly adding a calculated Image to the Map is possible.

1 Answer 1

2

You can calculate the backward difference in a ImageCollection by converting it to a list and mapping over that:

var ic_list = ic.sort('system:time_start').toList(ic.size())
print(ic_list)

// calculate "backward" gradient, i.e. Tn+1 - Tn. Reverse get indices to get "forward" gradient.
var ic_grad = ic_list.slice(0,-1)
  .zip(ic_list.slice(1))
  .map(function(f) { 
    return ee.Image(ee.List(f).get(1)).subtract(ee.Image(ee.List(f).get(0)))  
   })

print(ic_grad)

// add image from list to map
Map.addLayer(ee.Image(ic_grad.get(1)), {},'ic')

Adapted from an answer on the GEE developer forum.

2
  • I now got the List with the Gradient. But how do I pick an image from that List? ; Map.addLayer(ic_grad.get(1), {},'ic') returns "Cannot add an object of type <ComputedObject> to the map." Oct 28, 2018 at 16:38
  • You need to typecast the list element to an image: Map.addLayer(ee.Image(ic_grad.get(1)), {},'ic')
    – Kersten
    Oct 29, 2018 at 8:38

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.