expr min lq mean median uq max neval cld
textures_old <- f1_glcm(red_raster) 25.28074 25.81914 26.23389 26.1424 26.70709 27.1866 10 a
textures_new <- f2_GLCMTextures(red_quantized) 142.20192 142.26140 142.73769 142.3798 142.76346 144.9905 10 b
library(terra)
library(GLCMTextures)
library(glcm)
library(microbenchmark)
Data_dir <- "Namibia/Output/"
stk_file <- file.path(Data_dir, "stk_full.tif")
stk <- rast(stk_file)
# Clip to small area for testing
stk_crop <- crop(stk, ext(322400, 323000, 7885600, 7886200))
red <- stk_crop$red
red_raster <- raster::raster(red)
red_quantized <- quantize_raster(r = red, n_levels = 16,
method = "equal prob")
grey_levels <- 16
wind <- c(5, 5)
shift <- list(c(0,1), c(1,1), c(1,0), c(-1,1))
f1_glcm = function(x) {textures_old <- glcm::glcm(x = x,
statistics=c('variance',
'homogeneity',
'contrast',
'dissimilarity',
'entropy'),
shift=shift,
n_grey = grey_levels, window=wind)
names(textures_old) <- c("variance", "homogeneity",
"contrast", "dissimilarity", "entropy")
return(textures_old)
}
f2_GLCMTextures = function(x) {textures_new <- glcm_textures(r = x,
w=wind,
shift=shift,
metrics = c("glcm_variance",
"glcm_homogeneity",
"glcm_contrast",
"glcm_dissimilarity",
"glcm_entropy"),
quantization = "none",
n_levels=grey_levels, na.rm = TRUE)
names(textures_new) <- c("variance", "homogeneity",
"contrast","dissimilarity", "entropy")
return(textures_new)
}
microbenchmark(
textures_old <- f1_glcm(red_raster),
textures_new <- f2_GLCMTextures(red_quantized),
times=10
)