2

I'm using GLCM to get texture features from images to use them in classification algorithms like knn and decision tree. When I run the greycoprops function it returns an array of 4 elements for each feature as follows. Should I get the average of each feature to be used in my classification or how should I deal with them?

('Contrast = ', array([[0.88693423, 1.28768135, 1.11643255, 1.7071733 ]]))
Tonechas
  • 13,398
  • 16
  • 46
  • 80
rana hd
  • 355
  • 3
  • 18

1 Answers1

3

From the docs, this is what greycoprops returns:

results : 2-D ndarray

2-dimensional array. results[d, a] is the property ‘prop’ for the d’th distance and the a’th angle.

You are getting a 1×4 array of contrast values because you passed 4 angles to graycomatrix. In order for the GLCM descriptor to be rotation-invariant it is a common practice to average the feature values computed for different angles and the same distance. Have a look at this paper for a more in depth explanation on how to achieve GLCM features that are robust against rotation.

Demo

In [37]: from numpy import pi

In [38]: from skimage import data

In [39]: from skimage.feature.texture import greycomatrix, greycoprops

In [40]: img = data.camera()

In [41]: greycoprops(greycomatrix(img, distances=[1], angles=[0]), 'contrast')
Out[41]: array([[34000139]], dtype=int64)

In [42]: greycoprops(greycomatrix(img, distances=[1, 2], angles=[0]), 'contrast')
Out[42]: 
array([[ 34000139],
       [109510654]], dtype=int64)

In [43]: greycoprops(greycomatrix(img, distances=[1, 2], angles=[0, pi/4]), 'contrast')
Out[43]: 
array([[ 34000139,  53796929],
       [109510654,  53796929]], dtype=int64)

In [44]: greycoprops(greycomatrix(img, distances=[1], angles=[0, pi/4, pi/2]), 'contrast')
Out[44]: array([[34000139, 53796929, 20059013]], dtype=int64)
Community
  • 1
  • 1
Tonechas
  • 13,398
  • 16
  • 46
  • 80