google-earth-engine – How to Highlight Specific Pixels in an Image Using Masking

digital image processinggoogle-earth-engine

The two images below are the same.

In the images, the value of each pixel corresponds to a date in milliseconds.

enter image description here

In the top image, the pixels with the higher values – more recent date – are highlighted, while those with lower values are less highlighted.

The bottom image represents the raw mask of the image.

I imagine it is something to do with the masking of the image, but I am still figuring out what processing or operation was done to get this result.

Any ideas?

Code: https://code.earthengine.google.com/27a90e3abd360f7334ea41d0a4a9a9f6

Best Answer

Since you said that you tried clamp(), I'm assuming that you want the values reclassified.

var alerts = ee.ImageCollection('projects/radar-wur/raddalert/v1');
var geography = 'sa';

var latestAlert = ee.Image(
  alerts
    .filter(ee.Filter.eq('layer', 'alerts'))
    .filter(ee.Filter.eq('geography', geography))
    .sort('system:time_end', false)
    .first());

var confirmedAlertMask = latestAlert.select('Alert').eq(3);

var timeStart = ee.Date(latestAlert.get('system:time_start'));
var timeEnd = ee.Date(latestAlert.get('system:time_end'));
var differenceInDays = timeEnd.difference(timeStart, 'day');

// YYDOY (Year-Year-Day-of-Year).
var from = ee.List.sequence(0, differenceInDays).map(function(d) {
  return ee.Number.parse(
    timeStart.advance(d, 'day').format('yyDDD'))
    .subtract(1);
});

// Milliseconds.
var to = ee.List.sequence(0, differenceInDays)
  .map(function(d) {
    return timeStart.advance(d, 'day').millis();
  });

var alertInMillis = latestAlert
  .select('Date')
  // .updateMask(confirmedAlertMask)
  .remap(from, to)
  .rename('alertDate');

// Classifying, or reclassing the values.
var classValues = [0, 1, 2, 3];
var remapValues = ee.List.sequence({start:0, end:1, count:4});
var remapVal = ee.List.sequence({start: 0, end:1, count:3});
var label = 'lc';
var latestRmap = latestAlert.remap(classValues, remapValues).rename(label).toByte();

print(latestRmap, 'remap')

// Iago's original maps, alert in milliseconds
Map.addLayer(alertInMillis.updateMask(confirmedAlertMask.mask()), {}, 'Millis mask Raw');
Map.addLayer(alertInMillis.mask(), {}, 'Millis mask Smoothed');

// Iago's maps without ".mask()"
Map.addLayer(alertInMillis.updateMask(confirmedAlertMask), {}, 'Millis Raw');
Map.addLayer(alertInMillis, {}, 'Millis Smoothed');

// Alert in days, without a mask
Map.addLayer(latestAlert.updateMask(confirmedAlertMask), {}, 'No Mask Raw');
Map.addLayer(latestAlert, {}, 'No Mask Smoothed');

// Alert in days, with a mask
Map.addLayer(latestAlert.updateMask(confirmedAlertMask).mask(), {}, 'Mask Raw');
Map.addLayer(latestAlert.mask(), {}, 'Mask Smoothed');

// Original data, same as Alert in days without mask
Map.addLayer(latestAlert, {}, 'latest')

// Original data reclassed
Map.addLayer(latestRmap, {}, 'lc')
Map.setCenter(-65.81, -9.198, 8);

https://code.earthengine.google.com/5245cc7b6205254f99f3e888b785659c