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). 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:
// 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?
I am using the Python API, so answers in Python would be ideal, but any advice would be much appreciated!
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. Luminance is calculated as
0.3R + 0.59G + 0.11B.I've put together some Python code to create a Luminance layer here:
Here is a Java example that works in GEE Code Editor as well: