I want to calculate GLCM with 488 raster files. Because of the enormous calculation time i want to use all the power of my multicore processor (AMD Phenom II 6-core).
library("glcm")
library(raster)
library(devtools)
install_github('azvoleff/glcm')
setwd(working dir.)
rasters <- list.files()[grep("()\\w*.tif", list.files())]
statistics <- c("mean", "variance", "homogeneity", "contrast", "dissimilarity", "entropy","second_moment", "correlation")
shift1 <- c(0,0,1,1)
shift2 <- c(0,1,0,1)
for (j in 1:length(rasters)){
raster1 <- raster(rasters[j])
for (i in 1:length(statistics)){
for (k in 1:length(shift1)){
GLCM <- glcm(raster1, window=c(11,11), statistics=statistics[i], shift = c(shift1[k],shift2[k]), na_opt="ignore")
file <- paste("./GLCM/", substr(tiles[j],0,nchar(tiles[j])-4),"_", statistics[i], "_shift_",shift1[k], shift2[k] , ".tif", sep="")
writeRaster(GLCM, filename = file, type = "GTIFF")
}
}
gc()
}
I searched the internet for multicore solutions in R, but could not find out which one is up to date. So I hope someone can help me.