glcm icon indicating copy to clipboard operation
glcm copied to clipboard

Mirrored shifts don't produce equivalent results

Open ailich opened this issue 3 years ago • 0 comments

The documentation states states that "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." However, I believe that is only true if the GLCM is constructed in a symmetric way (that is why ENVI averages over 8 directions). For example, if a symmetric GLCM is used, I'd expect a 45 degree shift and a 225 degree shift should produce equivalent results but I get different results. Additionally, this introduces some ambiguity to mean and variance (as well as correlation which is calculated using mean and variance) as there is µi and µj for mean and σi and σj for the variance (these are equivalent in a symmetric GLCM; see formulas in the Hall-Beyer texture tutorial).

library(raster)
library(terra)
library(glcm)

r<- raster(rast(volcano, extent= ext(2667400, 2667400 + ncol(volcano)*10, 6478700, 6478700 + nrow(volcano)*10), crs = "EPSG:27200"))

t1a<- glcm(r, statistics=c("mean", "variance", "homogeneity", "contrast", "dissimilarity", "entropy", "second_moment", "correlation"), n_grey= 32, window =c(3,3), shift= c(1, 1), na_opt = "any") #45 degree shift

t1b<- glcm(r, statistics=c("mean", "variance", "homogeneity", "contrast", "dissimilarity", "entropy", "second_moment", "correlation"), n_grey= 32, window =c(3,3), shift= c(-1, -1), na_opt = "any") #225 degree shift

plot(t1a-t1b) #ab diff

148693550-b710ebe8-27b9-4a18-bf55-bcf4b5d6def2

ailich avatar Feb 05 '22 00:02 ailich