samedi 8 avril 2017

Google Earth Engine: How can I perform image calculations with random values pixel by pixel?

I would like to perform some calculations on an ee.Image pixel by pixel, however, the result calculated must obey a probabilistic Gaussian distribution, so some pixels will be modified and others not. I already coded a probabilistic function but I don't know how to apply it to each pixel in GEE. Is there any way to do that?

I already tried something like the following, but the same random number is used for every pixel, and that is not what I want.

Trial 1)

var result = img.where(img.lte(32 + Math.floor((Math.random() * 10) + 1)),1);

Trial 2)

var result = img.expression(
    '(B1 > 32 + P) ? 1', {
    'P': Math.floor((Math.random() * 10) + 1),
    'B1': img.select('B1')});

Trial 3)

var result = img.expression(
    'P > 10 ? 1', {
    'P': MyProbabilisticFunction(),
    'B1': img.select('B1')});

I also tried to use the following to generate a "probabilistic" image to perform my calculations but, since I have several classes in the same raster, the probability of the "event" is not quite right.

Trial 4)

var rd = ee.FeatureCollection.randomPoints(geometry,1000,Math.floor((Math.random() * 10) + 1));
var prob = rd.draw('000000',5,0).select('vis-red');
var result = img.where(prob.eq(0),1);




Aucun commentaire:

Enregistrer un commentaire