Announcement: All noncommercial projects registered to use Earth Engine before April 15, 2025 must verify noncommercial eligibility to maintain Earth Engine access.
Stay organized with collections
Save and categorize content based on your preferences.
Earth Engine has several special methods for estimating spatial texture. When
the image is discrete valued (not floating point), you can use image.entropy()
to compute the
entropy
in a neighborhood:
Note that the NIR band is scaled to 8-bits prior to calling entropy()
since the entropy computation takes discrete valued inputs. The non-zero elements in the
kernel specify the neighborhood.
Another way to measure texture is with a gray-level co-occurrence matrix (GLCM). Using
the image and kernel from the previous example, compute the GLCM-based contrast as follows:
Local measures of spatial association such as Geary’s C
(Anselin 1995) can be computed in Earth Engine using
image.neighborhoodToBands(). Using the image from the previous example:
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2023-10-06 UTC."],[[["\u003cp\u003eEarth Engine provides various methods for estimating spatial texture, including entropy, GLCM, and Geary's C.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eimage.entropy()\u003c/code\u003e method calculates entropy in a neighborhood for discrete-valued images.\u003c/p\u003e\n"],["\u003cp\u003eGray-level co-occurrence matrix (GLCM) texture measures, such as contrast, can be computed using \u003ccode\u003eimage.glcmTexture()\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eSpatial association, like Geary's C, can be calculated by using \u003ccode\u003eimage.neighborhoodToBands()\u003c/code\u003e to analyze neighborhood relationships.\u003c/p\u003e\n"],["\u003cp\u003eNeighborhood statistics, including standard deviation, offer another approach to texture analysis, as demonstrated on the Statistics of Image Neighborhoods page.\u003c/p\u003e\n"]]],["Earth Engine provides tools for estimating spatial texture. `image.entropy()` calculates entropy in a discrete-valued image neighborhood, using a kernel to define that neighborhood. `image.glcmTexture()` computes gray-level co-occurrence matrix (GLCM) texture measures like contrast. `image.neighborhoodToBands()` enables the computation of spatial associations like Geary's C, using a specified kernel and neighborhood weights. Standard deviation can also be used as explained in the earth-engine documentation.\n"],null,["# Texture\n\nEarth Engine has several special methods for estimating spatial texture. When\nthe image is discrete valued (not floating point), you can use `image.entropy()`\nto compute the\n[entropy](http://en.wikipedia.org/wiki/Entropy_(information_theory))\nin a neighborhood:\n\n### Code Editor (JavaScript)\n\n```javascript\n// Load a high-resolution NAIP image.\nvar image = ee.Image('USDA/NAIP/DOQQ/m_3712213_sw_10_1_20140613');\n\n// Zoom to San Francisco, display.\nMap.setCenter(-122.466123, 37.769833, 17);\nMap.addLayer(image, {max: 255}, 'image');\n\n// Get the NIR band.\nvar nir = image.select('N');\n\n// Define a neighborhood with a kernel.\nvar square = ee.Kernel.square({radius: 4});\n\n// Compute entropy and display.\nvar entropy = nir.entropy(square);\nMap.addLayer(entropy,\n {min: 1, max: 5, palette: ['0000CC', 'CC0000']},\n 'entropy');\n```\n\nNote that the NIR band is scaled to 8-bits prior to calling `entropy()`\nsince the entropy computation takes discrete valued inputs. The non-zero elements in the\nkernel specify the neighborhood.\n\nAnother way to measure texture is with a gray-level co-occurrence matrix (GLCM). Using\nthe image and kernel from the previous example, compute the GLCM-based contrast as follows:\n\n### Code Editor (JavaScript)\n\n```javascript\n// Compute the gray-level co-occurrence matrix (GLCM), get contrast.\nvar glcm = nir.glcmTexture({size: 4});\nvar contrast = glcm.select('N_contrast');\nMap.addLayer(contrast,\n {min: 0, max: 1500, palette: ['0000CC', 'CC0000']},\n 'contrast');\n```\n\nMany measures of texture are output by `image.glcm()`. For a complete\nreference on the outputs, see\n[Haralick et al.\n(1973)](http://ieeexplore.ieee.org/xpls/abs_all.jsp?arnumber=4309314&tag=1) and\n[Conners et al.\n(1984)](http://www.sciencedirect.com/science/article/pii/0734189X8490197X).\n\nLocal measures of spatial association such as Geary's C\n[(Anselin 1995)](http://onlinelibrary.wiley.com/doi/10.1111/j.1538-4632.1995.tb00338.x/abstract) can be computed in Earth Engine using\n`image.neighborhoodToBands()`. Using the image from the previous example:\n\n### Code Editor (JavaScript)\n\n```javascript\n// Create a list of weights for a 9x9 kernel.\nvar row = [1, 1, 1, 1, 1, 1, 1, 1, 1];\n// The center of the kernel is zero.\nvar centerRow = [1, 1, 1, 1, 0, 1, 1, 1, 1];\n// Assemble a list of lists: the 9x9 kernel weights as a 2-D matrix.\nvar rows = [row, row, row, row, centerRow, row, row, row, row];\n// Create the kernel from the weights.\n// Non-zero weights represent the spatial neighborhood.\nvar kernel = ee.Kernel.fixed(9, 9, rows, -4, -4, false);\n\n// Convert the neighborhood into multiple bands.\nvar neighs = nir.neighborhoodToBands(kernel);\n\n// Compute local Geary's C, a measure of spatial association.\nvar gearys = nir.subtract(neighs).pow(2).reduce(ee.Reducer.sum())\n .divide(Math.pow(9, 2));\nMap.addLayer(gearys,\n {min: 20, max: 2500, palette: ['0000CC', 'CC0000']},\n \"Geary's C\");\n```\n\nFor an example of using neighborhood standard deviation to compute image texture, see the\n[Statistics of Image Neighborhoods page](/earth-engine/guides/reducers_reduce_neighborhood)."]]