Google Earth Engine-从ImageCollection Python API导出RGB图像

时间:2018-10-24 17:36:40

标签: python-3.x google-earth-engine

我在使用Google Earth Engine python API生成基于ImageCollection的RGB图像时遇到一些问题。

基本上是将ImageCollection转换为Image,我应用了中值缩减。减少之后,我在需要定义最小和最大等不同变量的地方应用可视化功能。问题在于这两个值与图像有关。

dataset = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR')
        .filterBounds(ee.Geometry.Polygon([[39.05789266, 13.59051553],
                       [39.11335033, 13.59051553],
                       [39.11335033, 13.64477783],
                       [39.05789266, 13.64477783],
                       [39.05789266, 13.59051553]]))
        .filterDate('2016-01-01', '2016-12-31')
        .select(['B4', 'B3', 'B2'])

reduction = dataset.reduce('median')
            .visualize(bands=['B4_median', 'B3_median', 'B2_median'],
                         min=0,
                         max=3000,
                         gamma=1)

因此,对于每个不同的图像,我需要处理这两个可以明显改变的值。由于我需要生成的图像数量很多,因此无法手动完成。我不知道如何克服这个问题,也找不到任何答案。一个想法是找到图像的最小值和最大值。但是我没有找到任何允许在Javascript或python API上执行此操作的函数。

我希望有人能够帮助我。

1 个答案:

答案 0 :(得分:1)

您可以使用img.reduceRegion()来获取所需区域和每个导出图像的图像统计信息。您必须将区域缩小的结果调用到可视化函数中。这是一个示例:

geom = ee.Geometry.Polygon([[39.05789266, 13.59051553],
                   [39.11335033, 13.59051553],
                   [39.11335033, 13.64477783],
                   [39.05789266, 13.64477783],
                   [39.05789266, 13.59051553]])

dataset = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR')\
    .filterBounds(geom)\
    .filterDate('2016-01-01', '2016-12-31')\
    .select(['B4', 'B3', 'B2'])

reduction = dataset.median()

stats = reduction.reduceRegion(reducer=ee.Reducer.minMax(),geometry=geom,scale=100,bestEffort=True)

statDict = stats.getInfo()

prettyImg = reduction.visualize(bands=['B4', 'B3', 'B2'],
                     min=[statDict['B4_min'],statDict['B3_min'],statDict['B2_min']]
                     max=[statDict['B4_max'],statDict['B3_max'],statDict['B2_max']],
                     gamma=1)

使用这种方法,我得到如下输出图像:

我希望这会有所帮助!