Skip to content

Instantly share code, notes, and snippets.

@benkamphaus
Created May 5, 2016 04:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benkamphaus/71947077ff6207f1636e4b37b990cbde to your computer and use it in GitHub Desktop.
Save benkamphaus/71947077ff6207f1636e4b37b990cbde to your computer and use it in GitHub Desktop.
How to use skimage glcm routines to create a glcm image.
import numpy as np
import skimage
from skimage.feature import greycomatrix, greycoprops
def glcm_image(img, measure="dissimilarity"):
"""TODO: allow different window sizes by parameterizing 3, 4. Also should
parameterize direction vector [1] [0]"""
texture = np.zeros_like(sub)
# quadratic looping in python w/o vectorized routine, yuck!
for i in range(img.shape[0] ):
for j in range(sub.shape[1] ):
# don't calculate at edges
if (i < 3) or \
(i > (img.shape[0])) or \
(j < 3) or \
(j > (img.shape[0] - 4)):
continue
# calculate glcm matrix for 7 x 7 window, use dissimilarity (can swap in
# contrast, etc.)
glcm_window = img[i-3: i+4, j-3 : j+4]
glcm = greycomatrix(glcm_window, [1], [0], symmetric = True, normed = True )
texture[i,j] = greycoprops(glcm, measure)
return texture
@rezwanh001
Copy link

What is the value of sub of this code?

@dcharry
Copy link

dcharry commented Jun 6, 2018

What is the value of (sub)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment