【问题标题】:Convert RGB image to single band grayscale image within Google Earth Engine using Python API使用 Python API 在 Google Earth Engine 中将 RGB 图像转换为单波段灰度图像
【发布时间】:2019-08-23 22:55:33
【问题描述】:

我希望使用灰度共现矩阵 (GLCM) 在 Google 地球引擎 (GEE) 中提取一组 RGB 卫星图像纹理的摘要统计信息。 GEE 有一个内置的 image.glcm() 函数来执行此操作,但是此页面 (https://developers.google.com/earth-engine/image_texture) 中的示例代码表明它需要单个波段作为输入:

// Load a high-resolution NAIP image.
var image = ee.Image('USDA/NAIP/DOQQ/m_3712213_sw_10_1_20140613');

// Get the NIR band.
var nir = image.select('N');

// Compute the gray-level co-occurrence matrix (GLCM), get contrast.
var glcm = nir.glcmTexture({size: 4});
var contrast = glcm.select('N_contrast');
Map.addLayer(contrast,
             {min: 0, max: 1500, palette: ['0000CC', 'CC0000']},
             'contrast');

有没有办法在 GEE 中将 RGB 图像转换为单波段灰度图像?

我正在使用 Python API,因此 Python 中的答案将是理想的,但任何建议都将不胜感激!

【问题讨论】:

  • var image = ee.Image(...).convert('LA'); 工作吗?
  • 您好 Elias,我无法在 Google 地球引擎代码编辑器中找到 .convert('LA'); 作为函数,而且它似乎不是 ee.Image() 的属性。你成功使用了吗?

标签: python rgb google-earth-engine glcm


【解决方案1】:

好的,我想出了一个方法。这篇论文 (https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3254613/) 评估了不同 RGB 到灰度转换的性能,发现 Luminance 在纹理识别方面表现特别好,在对象检测方面表现中等,因此是 GLCM 分析的好选择。亮度计算为0.3R + 0.59G + 0.11B

我在这里整理了一些 Python 代码来创建一个亮度层:

image = ee.Image("COPERNICUS/S2/20160620T072622_20160620T075216_T36LYJ")

grayscale = image.expression(
      '(0.3 * R) + (0.59 * G) + (0.11 * B)', {
      'R': image.select(['B4']),
      'G': image.select(['B3']),
      'B': image.select(['B2'])
})

下面是一个同样适用于 GEE 代码编辑器的 Java 示例:

var image = ee.Image("COPERNICUS/S2/20160620T072622_20160620T075216_T36LYJ");

var grayscale = image.expression(
      '(0.3 * R) + (0.59 * G) + (0.11 * B)', {
      'R': image.select('B4'),
      'G': image.select('B3'),
      'B': image.select('B2')
});

Map.setCenter(35.524263, -14.955732, 9);
Map.addLayer(grayscale, {min:700, max:1300}, 'Grayscale');

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-03-29
    • 1970-01-01
    • 2012-08-25
    • 2018-08-15
    • 1970-01-01
    • 2014-02-26
    • 2014-12-22
    相关资源
    最近更新 更多