Created
May 5, 2016 04:55
-
-
Save benkamphaus/71947077ff6207f1636e4b37b990cbde to your computer and use it in GitHub Desktop.
How to use skimage glcm routines to create a glcm image.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What is the value of
sub
of this code?