if (FALSE) {
require(fastGLCM)
require(OpenImageR)
file_im = system.file('images', 'Sugar_Cane_Bolivia_PlanetNICFI.png', package = 'fastGLCM')
im = readImage(file_im)
#...................................
# convert to gray and make sure that
# pixel values are between 0 and 255
#...................................
im = rgb_2gray(im)
im = im * 255
MIN = min(as.vector(im))
MAX = max(as.vector(im))
#...............
# methods to use
#...............
methods_py = c('mean',
'std',
'contrast',
'dissimilarity',
'homogeneity',
'ASM_Energy',
'max',
'entropy')
init = fastglcm$new()
lst_glcm_py = list()
for (item_m in methods_py) {
cat(paste0('Method: ', item_m), '\n')
res_item = init$GLCM_compute(img = im,
method = item_m,
vmin = as.integer(MIN),
vmax = as.integer(MAX),
levels = as.integer(8),
ks = as.integer(5),
distance = 1.0,
angle = 0.0)
lst_glcm_py[[item_m]] = res_item
}
#..............................
# Create two different sublists
# for 'ASM' and 'Energy'
#..............................
lst_glcm_py = append(lst_glcm_py, list(lst_glcm_py[['ASM_Energy']][[1]]), after = 5)
names(lst_glcm_py)[6] = 'ASM'
lst_glcm_py = append(lst_glcm_py, list(lst_glcm_py[['ASM_Energy']][[2]]), after = 6)
names(lst_glcm_py)[7] = 'energy'
lst_glcm_py[['ASM_Energy']] = NULL
str(lst_glcm_py)
#.........................
# multi-plot of the output
#.........................
plot_multi_images(list_images = lst_glcm_py,
par_ROWS = 2,
par_COLS = 5,
titles = names(lst_glcm_py))
}
Run the code above in your browser using DataLab