3

The final input of my work will be quintile ee.Image objects. To test my display I would like to create an ee.Image with the value in each pixel set randomly in [1, 5] (only integer).

I have already an ee.Image that could be used as a base:

var data = ee.Image('Oxford/MAP/accessibility_to_cities_2015_v1_0')

I just want to rewrite every pixel in it.

Is there a simple way to do that in Google Earth Engine ?

5

You can create a random image with ee.Image.random(). It will be between 0 and 1. To convert it to ints between 1 and 5, you can do this:

ee.Image.random().multiply(5).add(1).byte()

If you want to use the same mask as your data image, you can do this:

var image = ee.Image.random().multiply(5).add(1).byte()
  .updateMask(data.mask())

https://code.earthengine.google.com/fbbe60d68bff6883556034bffbffcdc2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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