GLCM feature texture extraction

fastGLCM_Rcpp(
data,
methods,
levels = 8,
kernel_size = 5,
distance = 1,
angle = 0,
dir_save = NULL,
verbose = FALSE
)

## Arguments

data

a numeric matrix

methods

a vector of character strings. One or all of the following: 'mean', 'std', 'contrast', 'dissimilarity', 'homogeneity', 'ASM', 'energy', 'max', 'entropy'

levels

an integer specifying the window size. This parameter will create a mask of size levels x levels internally

kernel_size

an integer specifying the kernel size. A kernel of 1's will be created and the cv2.filter2D filter will be utilized for the convolution

distance

a numeric value specifying the pixel pair distance offsets (a 'pixel' value such as 1.0, 2.0 etc.)

angle

a numeric value specifying the pixel pair angles (a 'degree' value such as 0.0, 30.0, 45.0, 90.0 etc.)

dir_save

either NULL or a character string specifying a valid path to a directory where the output GLCM matrices (for the specified 'methods') will be saved. By setting this parameter to a valid directory the memory usage will be decreased.

an integer value specifying the number of cores to run in parallel

verbose

a boolean. If TRUE then information will be printed out in the console

## Value

a list consisting of one or more GLCM features

## Details

The following are two factors which (highly probable) will increase memory usage during computations:

• 1st. the image size (the user might have to resize the image first)

• 2nd. the 'levels' parameter. The bigger this parameter the more matrices will be initialized and more memory will be used. For instance if the 'levels' parameter equals to 8 then 8 * 8 = 64 matrices of equal size to the input image will be initialized. That means if the image has dimensions (2745 x 2745) and the image-object size is approx. 60 MB then by initializing 64 matrices the memory will increase to 3.86 GB.

This function is an Rcpp implementation of the python fastGLCM module. When using each function separately by utilizing all threads it's slightly faster compared to the python vectorized functions, however it's a lot faster when computing all features at once.

The dir_save parameter allows the user to save the GLCM's as .csv files to a directory. That way the output GLCM's matrices won't be returned in the R session (reduced memory usage). However, by saving the GLCM's to .csv files the computation time increases.

## References

https://github.com/tzm030329/GLCM

## Examples


require(fastGLCM)
require(OpenImageR)
require(utils)

temp_dir = tempdir(check = FALSE)
# temp_dir

zip_file = system.file('images', 'JAXA_Joso-City2_PAN.tif.zip', package = "fastGLCM")
utils::unzip(zip_file, exdir = temp_dir)
path_extracted = file.path(temp_dir, 'JAXA_Joso-City2_PAN.tif')

dim(im)
#> [1] 1555 1414

#...............................................
# resize the image and adjust pixel values range
#...............................................

im = resizeImage(im, 500, 500, 'nearest')
im = OpenImageR::norm_matrix_range(im, 0, 255)

#---------------------------------
# computation of all GLCM features
#---------------------------------

methods = c('mean',
'std',
'contrast',
'dissimilarity',
'homogeneity',
'ASM',
'energy',
'max',
'entropy')

res_glcm = fastGLCM_Rcpp(data = im,
methods = methods,
levels = 8,
kernel_size = 5,
distance = 1.0,
angle = 0.0,