glcm: Image texture measures from grey-level co-occurrence matrices...

Description Usage Arguments Details Value References Examples

View source: R/glcm.R

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

1
2
3
4
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.

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.

Value

A RasterLayer or RasterStack with the requested GLCM texture measures.

References

Lu, D., and M. Batistella. 2005. Exploring TM image texture and its relationships with biomass estimation in Rondô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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# 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)

## End(Not run)

Example output

, , glcm_variance

     [,1]      [,2]     [,3] [,4] [,5]
[1,]   NA        NA       NA   NA   NA
[2,]   NA  99.29557 122.3303   NA   NA
[3,]   NA 247.83724 287.6116   NA   NA
[4,]   NA        NA       NA   NA   NA
[5,]   NA        NA       NA   NA   NA

, , glcm_variance

     [,1] [,2]     [,3] [,4] [,5]
[1,]   NA   NA       NA   NA   NA
[2,]   NA   NA 123.1304   NA   NA
[3,]   NA   NA 288.9082   NA   NA
[4,]   NA   NA       NA   NA   NA
[5,]   NA   NA       NA   NA   NA

Loading required package: raster
Loading required package: sp

glcm documentation built on March 26, 2020, 7:47 p.m.