# Texture

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:

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

// Zoom to San Francisco, display.
Map.setCenter(-122.466123, 37.769833, 17);

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

// Define a neighborhood with a kernel.

// Compute entropy and display.
var entropy = nir.entropy(square);
{min: 1, max: 5, palette: ['0000CC', 'CC0000']},
'entropy');
```

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:

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

Many measures of texture are output by `image.glcm()`. For a complete reference on the outputs, see Haralick et al. (1973) and Conners et al. (1984).

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:

```// Create a list of weights for a 9x9 kernel.
var row = [1, 1, 1, 1, 1, 1, 1, 1, 1];
// The center of the kernel is zero.
var centerRow = [1, 1, 1, 1, 0, 1, 1, 1, 1];
// Assemble a list of lists: the 9x9 kernel weights as a 2-D matrix.
var rows = [row, row, row, row, centerRow, row, row, row, row];
// Create the kernel from the weights.
// Non-zero weights represent the spatial neighborhood.
var kernel = ee.Kernel.fixed(9, 9, rows, -4, -4, false);

// Convert the neighborhood into multiple bands.
var neighs = nir.neighborhoodToBands(kernel);

// Compute local Geary's C, a measure of spatial association.
var gearys = nir.subtract(neighs).pow(2).reduce(ee.Reducer.sum())
.divide(Math.pow(9, 2));