使用GLCM减少纹理分析中的运行时间[Python]

时间:2016-08-15 13:26:16

标签: python image-processing scikit-image glcm

我正在研究6641x2720图像,使用移动的GLCM(灰度级共生矩阵)窗口生成其特征图像(Haralick功能,如对比度,第二时刻等)。但它需要永远运行。 代码工作正常,因为我在较小的图像上测试过。但是,我需要让它运行得更快。将尺寸减小到25%(1661x680),运行 30分钟。如何让它运行得更快?这是代码:

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)

0 个答案:

没有答案