# Gray-level co-occurrence matrix feature computation

I have many images and want to compute the GLCM properties for every image. Below my code that runs many hours to complete the task:

import numpy as np
from skimage.feature import greycomatrix, greycoprops

ANGLES = [0., np.pi/4., np.pi/2., 3.*np.pi/4.]
DISTANCES = [1,2]
properties = ["correlation", "contrast", "homogeneity", "energy"]
n_img = 1000

I = np.random.randint(0,255,size=(n_img, 100, 100))

stats = []
for k in range(n_img):
glcm = greycomatrix(I[k], distances=DISTANCES, angles=ANGLES, levels=256, symmetric=True, normed=True)
prop = [np.mean(greycoprops(glcm, properties[i])) for i in range(len(properties))]
stats.append(prop)
stats = np.array(stats)


This code is a real bottleneck. How can parallelize the task? Are there other ways to speed up the code?

• – juvian Oct 26 '18 at 15:44