glcm (version 1.6.3)

glcm: Image texture measures from grey-level co-occurrence matrices (GLCM)

Description

This function supports calculating texture statistics derived from grey-level co-occurrence matrices (GLCMs). The default textures are calculated using a 45 degree shift. See Details for other options.

Usage

glcm(x, n_grey = 32, window = c(3, 3), shift = c(1, 1), statistics = 
c("mean", "variance", "homogeneity", "contrast", "dissimilarity", "entropy", 
"second_moment", "correlation"), min_x=NULL, max_x=NULL, na_opt="any", 
na_val=NA, scale_factor=1, asinteger=FALSE)

Arguments

x

a RasterLayer or matrix

n_grey

number of grey levels to use in texture calculation

window

the window size to consider for texture calculation as a two element integer vector (number of rows, number of columns)

shift

a list or matrix specifying the shift to use. See Details.

statistics

A list of GLCM texture measures to calculate (see Details).

min_x

minimum value of input RasterLayer (optional, glcm will calculate if not supplied). Useful when running glcm over blocks of a raster.

max_x

maximum value of input RasterLayer (optional, glcm will calculate if not supplied). Useful when running glcm over blocks of a raster.

na_opt

How to handle NA values in x. Can be set to "ignore", "any" or "center". If set to "any", all textures statistics for a given pixel will be set to NA if there are any NA values in the window around that pixel. If set to "center" this will only occur if the center value is an NA. If set to "ignore", NA values in window will be ignored.

na_val

the value to use to fill NA values on edges of x where textures cannot be calculated due to the window falling outside of the image, and as necessary depending on the chosen na_opt.

scale_factor

factor by which to multiply results. Useful if rounding results to integers (see asinteger argument).

asinteger

whether to round results to nearest integer. Can be used to save space by saving results as, for example, an 'INT2S' raster.

Value

A RasterLayer or RasterStack with the requested GLCM texture measures.

Details

The statistics parameter should be a list, and can include any (one or more) of the following: 'mean', 'mean_ENVI', 'variance', 'variance_ENVI', 'homogeneity', 'contrast', 'dissimilarity', 'entropy', 'second_moment', and/or 'correlation'. By default all of the statistics except for "mean_ENVI" and "variance_ENVI" will be returned .

shift can be one of:

  1. a two element integer vector giving the shift (Q in Gonzalez and Woods, 2008), as (number of rows, number of columns).

  2. a list of integer vectors of length 2 specifying multiple (row, col) shifts over which to calculate the GLCM textures. For example: shift=list(c(1,1), c(-1,-1))

  3. a matrix with two columns specifying, in rows, multiple (row, col) shifts over which to calculate the GLCM textures. For example: shift=matrix(c(1,1,-1,-1), byrow=TRUE, ncol=2)

If multiple shifts are supplied, glcm will calculate each texture statistic using all the specified shifts, and return the mean value of the texture for each pixel. To calculate GLCM textures over "all directions" (in the terminology of commonly used remote sensing software), use: shift=list(c(0,1), c(1,1), c(1,0), c(1,-1)). This will calculate the average GLCM texture using shifts of 0 degrees, 45 degrees, 90 degrees, and 135 degrees.

References

Lu, D., and M. Batistella. 2005. Exploring TM image texture and its relationships with biomass estimation in Rond<U+00F4>nia, Brazilian Amazon. Acta Amazonica 35:249--257.

Gonzalez, R. C. 2008. Digital image processing. 3rd ed. Prentice Hall, Upper Saddle River, N.J, pages 830--836.

Haralick, R. M., K. Shanmugam, and I. Dinstein. 1973. Textural features for image classification. IEEE Transactions on Systems, Man and Cybernetics SMC-3:610--621.

Pratt, W. K. 2007. Digital image processing: PIKS Scientific inside. 4th ed. Wiley-Interscience, Hoboken, N.J pages 540--541, 563--566.

Examples

Run this code
# NOT RUN {
# Calculate GLCM textures on a matrix
d <- matrix(seq(1:25), nrow=5, ncol=5, byrow=TRUE)

# Calculate using default 90 degree shift
glcm(d, statistics=c('variance'))

# Calculate over all directions
glcm(d, shift=list(c(0,1), c(1,1), c(1,0), c(1,-1)), 
     statistics=c('variance'))

# }
# NOT RUN {
# Calculate GLCM textures on a raster
require(raster)
# Calculate using default 90 degree shift
textures_shift1 <- glcm(raster(L5TSR_1986, layer=1))
plot(textures_shift1)

# Calculate over all directions
textures_all_dir <- glcm(raster(L5TSR_1986, layer=1),
                         shift=list(c(0,1), c(1,1), c(1,0), c(1,-1)))
plot(textures_all_dir)
# }

Run the code above in your browser using DataLab