2

I'm using this code to extract GLCM features for a certain image but it gives me a value error

Code:

from PIL import Image
from skimage.feature import greycomatrix, greycoprops
fname = 'trial.jpg'
img = Image.open(fname).convert("L")
img = img.resize((224, 224))
test_glcm = greycomatrix(img, [1], [np.pi/2], 256, symmetric=True, normed=True)

Error:

ValueError buffer source array is read-only

Does anyone knows what that means, or what may be the problem in the code?

Tonechas
  • 13,398
  • 16
  • 46
  • 80
Lilly
  • 55
  • 9

1 Answers1

2

To fix the error you just need to convert the PIL image into a NumPy array like this:

test_glcm = greycomatrix(np.array(img), [1], [np.pi/2], 256, symmetric=True, normed=True)
Tonechas
  • 13,398
  • 16
  • 46
  • 80