3

I have seen this paper yesterday. In this paper the features are taken as contrast, local homogeneity and energy, which all are a single values (as per my knowledge) but according to skimage fuction greycomatrix, the parameters passed to these that are distances and angles (which can be more than one).

Here is my code:

import numpy as np
import cv2
from skimage.feature import greycomatrix, greycoprops
from skimage import io, color, img_as_ubyte

img = cv2.imread('Grape___Black_rot28.JPG')
gray_image = cv2.cvtColor(img2, cv2.COLOR_BGR2GRAY)    

distances = [1, 2, 3]
angles = [0, np.pi/4, np.pi/2, 3*np.pi/4]
glcm = greycomatrix(gray_image, 
                    distances=distances, 
                    angles=angles,
                    symmetric=True,
                    normed=True)

properties = ['contrast', 'energy', 'homogeneity', 'correlation', 'dissimilarity']
contrast = greycoprops(glcm, properties[0])
energy = greycoprops(glcm, properties[1])
homogeneity = greycoprops(glcm, properties[2])
correlation = greycoprops(glcm, properties[3])
dissimilarity = greycoprops(glcm, properties[4])

What confuses me is if I generate a glcm of contrast property it will be of 3x4 size but according to the paper it is a single value and even if I consider all 3x4 values of all the properties as a feature, I bet it will have a over-fitting problem for svm model.

Tonechas
  • 13,398
  • 16
  • 46
  • 80

1 Answers1

1

From graycoproprops documentation:

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.

Your code yields a feature value for each distance-angle combination:

In [5]: len(distances)
Out[5]: 3

In [6]: len(angles)
Out[6]: 4

In [7]: contrast.shape
Out[7]: (3, 4)

A common practice to achieve rotation invariance consists in averaging feature values along the angles axis. By doing so, you will get as many feature values as you have distances:

In [11]: contrast = greycoprops(glcm, properties[0]).mean(axis=1)

In [12]: contrast.shape
Out[12]: (3,)
Community
  • 1
  • 1
Tonechas
  • 13,398
  • 16
  • 46
  • 80