重新分类图像集合中所有图像中的所有像素值 - GEE

Reclassify all pixel values in all of the images in an image collection - GEE

我是 GEE 的新手,所以这个问题的答案对你们大多数人来说可能很简单。我正在寻找一种方法来对图像集合中所有图像中的像素值进行重新分类。我正在处理来自全球地表水数据集的每月历史数据,并以三月至五月为目标。目前,水像素的值为 2,非水像素为 1,非采样像素(无数据)为 0。我想重新分类,使水 = 1,而不是水 = 0,以及所有内容否则被掩盖。我的代码如下:

var dataset = ee.ImageCollection('JRC/GSW1_2/MonthlyHistory')
.filterBounds(roi)
.map(function(image){return image.clip(roi)})
.filter(ee.Filter.calendarRange(3, 5, 'month'));
print(dataset);

这是不起作用的部分...

var reclassified = function(img) {
  return img.remap(([2, 1], [1, 0]), 'water');
};
var new_ds = dataset.map(reclassified)
print(new_ds);

你这里多了一组括号:

  return img.remap(([2, 1], [1, 0]), 'water');
                   ^              ^

这个错误的影响是像你写了 img.remap([1, 0], 'water') 一样继续,但失败了,因为 'water' 不能变成一个列表。

还有另一个问题:当您不使用命名参数形式时,您必须编写 所有 参数直到您要指定的最后一个可选参数。参数列表是remap(from, to, <i>defaultValue, bandName</i>),所以不需要写defaultValue .在 Earth Engine API 调用中,您可以将 null 用于您不想指定的任何可选参数:

  return img.remap([2, 1], [1, 0], null, 'water');

或者,您可以使用命名参数来获得相同的结果:

  return img.remap({
    from: [2, 1],
    to: [1, 0],
    bandName: 'water'
  });

或者,由于在这种特殊情况下您的图像只包含一个波段,您可以完全省略 bandName

  return img.remap([2, 1], [1, 0]);