I am working on 6641x2720 image to generate its feature images (Haralick features like contrast, second moment etc) using a moving GLCM(Grey level Co-occurrence matrix ) window. But it takes forever to run. The code works fine, as I have tested it on smaller images. But, I need to make it run faster. Reducing the dimensions to 25% (1661x680) it takes 30 minutes to run. How can I make it run faster ? Here's the code:
from skimage.feature import greycomatrix, greycoprops
import matplotlib.pyplot as plt
import numpy as np
from PIL import Image
import time
start_time = time.time()
img = Image.open('/home/student/python/test50.jpg').convert('L')
y=np.asarray(img, dtype=np.uint8)
#plt.imshow(y, cmap = plt.get_cmap('gray'), vmin = 0, vmax = 255)
contrast = np.zeros((y.shape[0], y.shape[1]), dtype = float)
for i in range(0,y.shape[0]):
for j in range(0,y.shape[1]):
if i < 2 or i > (y.shape[0]-3) or j < 2 or j > (y.shape[1]-3):
continue
else:
s = y[(i-2):(i+3), (j-2):(j+3)]
glcm = greycomatrix(s, [1], [0], symmetric = True, normed = True )
contrast[i,j] = greycoprops(glcm, 'contrast')
print("--- %s seconds ---" % (time.time() - start_time))
plt.imshow(contrast, cmap = plt.get_cmap('gray'), vmin = 0, vmax = 255)