0

I am using scikit-image's greycomatrix (GLCM) to extract features from an image. This method is quite fast, but when creating a feature map of an image with GLCM one needs to glide a window over the image and call greycomatrix once for each window. For a 256x256 image that is 65536 calls. This becomes very slow with simple Python loops. I have been searching high and low, but I cannot find an existing implementation of this window gliding method, so I have made it myself so far. It seems strange that this doesn't already exist within scikit-image since this is the primary way to use the GLCM.

In the scikit-image GLCM tutorial (http://scikit-image.org/docs/dev/auto_examples/plot_glcm.html) they only analyse a few individual windows and say nothing about gliding windows. That is not very helpful.

import numpy as np
from skimage.feature import greycomatrix
from skimage.data import coins

def glide(image, w, d, theta, levels=16):

    image = np.pad(image, int(w/2), mode='reflect')  # Add padding.
    M, N = image.shape
    feature_map = np.zeros((M, N))  # Placeholder for some feature.

    for m in xrange(0, M):
        for n in xrange(0, N):
            window = image[m:m+w, n:n+w]
            glcm = greycomatrix(window, d, theta, levels)
            # Do something with glcm: Find variance, entropy, etc.
            feature_map[m,n] = 1.  # Compute something here.

feature_map = glide(coins(), w=21, d=[5], theta=[0], levels=256)

This is my custom gliding window method. Does a more efficient version of this already exist within scikit-image or similar?

Tonechas
  • 13,398
  • 16
  • 46
  • 80
PaulMag
  • 3,928
  • 3
  • 18
  • 29
  • 3
    Perhaps the following are useful: ``skimage.util.view_as_windows``, ``skimage.util.view_as_blocks``, ``skimage.util.apply_parallel`` (see http://scikit-image.org/docs/dev/api/api.html) – Stefan van der Walt Oct 16 '15 at 22:38
  • @StefanvanderWalt Yes, this is it! `skimage.util.apply_parallel` does exactly what I need! This should be mentioned in the GLCM tutorial. However, I am unable to import it. `skimage.util.apply_parallel` just doesn't exist in my `skimage.util`... And I do have the latest version of `skimage` (0.11.3). What is going on here? `skimage.util.view_as_windows` works fine, but with this I still have to loop through all the windows, so it's a minor improvement. – PaulMag Oct 17 '15 at 15:44
  • That functionality will only be available in the next release. But I'm glad that it works for you! You can also just grab the source code from the Git repository. – Stefan van der Walt Oct 20 '15 at 17:36

0 Answers0