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.]
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 = np.array(stats)

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


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.