简体   繁体   English

使用Python API在Google Earth Engine中将RGB图像转换为单波段灰度图像

[英]Convert RGB image to single band grayscale image within Google Earth Engine using Python API

I wish to extract summary statistics on the texture of a set of RGB satellite images within Google Earth Engine (GEE) using a gray-level co-occurrence matrix (GLCM). 我希望使用灰度共生矩阵(GLCM)提取有关Google Earth Engine(GEE)中的一组RGB卫星图像的纹理的摘要统计信息。 GEE has a built in image.glcm() function to do this, however the example code from this page ( https://developers.google.com/earth-engine/image_texture ) suggests it requires a single band as input: 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');

Is there a way to convert an RGB image into a single band grayscale image within GEE? 有没有办法在GEE中将RGB图像转换为单波段灰度图像?

I am using the Python API, so answers in Python would be ideal, but any advice would be much appreciated! 我正在使用Python API,因此使用Python回答是理想的,但是任何建议将不胜感激!

OK, I figured out a method. 好,我想出了一种方法。 This paper ( https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3254613/ ) assessed the performance of different RGB to Grayscale conversions and found that Luminance performed particularly well for texture recognition and moderately well for object detection and so is a good bet for GLCM analysis. 本文( https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3254613/ )评估了不同RGB到灰度转换的性能,发现亮度在纹理识别方面表现特别出色,在物体检测和图像识别方面表现中等GLCM分析也是一个不错的选择。 Luminance is calculated as 0.3R + 0.59G + 0.11B . 亮度计算为0.3R + 0.59G + 0.11B

I've put together some Python code to create a Luminance layer here: 我在这里整理了一些Python代码来创建Luminance层:

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'])
})

Here is a Java example that works in GEE Code Editor as well: 这是一个在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');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM