#!/usr/bin/env python import numpy as np from skimage.feature import graycomatrix, graycoprops from time import perf_counter acc0 = 0.0 acc1 = 0.0 total = 0.0 nruns = 5000 for _ in range(nruns): a = np.random.uniform(0.0, 1.0, size=(100, 100)) image = np.floor(a * 256.0).astype(np.uint16) now = perf_counter() m = graycomatrix( image, distances=[1.0], angles=[0.0], levels=256 ) elapsed0 = perf_counter() - now _ = graycoprops(m, "contrast") _ = graycoprops(m, "homogeneity") _ = graycoprops(m, "dissimilarity") _ = graycoprops(m, "energy") _ = graycoprops(m, "ASM") _ = graycoprops(m, "correlation") t1 = perf_counter() - now elapsed1 = t1 - elapsed0 total += t1 acc0 += elapsed0 acc1 += elapsed1 print( "Took {:.7f}s + {:.7f}s = {:.7f}s on average for {} runs ({:.3f}s + {:.3f}s = {:.3f}s in total)".format( acc0 / nruns, acc1 / nruns, total / nruns, nruns, acc0, acc1, total));