title: How to use the scikit-image greycomatrix() -function in python?
body: <p>I'm trying to compute grey level co-occurrence matrices from images for feature extraction. I'm using <a href="https://scikit-image.org/docs/dev/api/skimage.feature.html?highlight=greycomatrix#skimage.feature.greycomatrix" rel="nofollow noreferrer"><code>greycomatrix</code></a> for the task but there seems to be something I don't understand about the process since I'm getting the following error: </p>
  
  <blockquote>
    <p>ValueError: buffer source array is read-only</p>
  </blockquote>
  
  <p>(The full trace can be found below)</p>
  
  <h2>So here's what I've done:</h2>
  
  <p>Converting the (PIL) image to grayscale with 8 quantization levels:</p>
  
  <pre><code>greyImg = img.convert('L', colors=8)
  </code></pre>
  
  <p>And then compute the glcm matrices:</p>
  
  <pre><code>glcm = greycomatrix(greyImg, distances=[1], angles=[0, np.pi/4, np.pi/2], 
                      symmetric=True, normed=True)
  </code></pre>
  
  <p>This results in a rather cryptic error:</p>
  
  <blockquote>
    <p>glcm = greycomatrix(img, distances=[1], angles=[0, np.pi/4, np.pi/2], levels=256, symmetric=True, normed=True)</p>
    
    <p>_glcm_loop(image, distances, angles, levels, P)  </p>
    
    <p>File "skimage/feature/_texture.pyx", line 18, in skimage.feature._texture._glcm_loop  </p>
    
    <p>File "stringsource", line 654, in View.MemoryView.memoryview_cwrapper  </p>
    
    <p>File "stringsource", line 349, in View.MemoryView.memoryview._cinit__
    ValueError: buffer source array is read-only</p>
  </blockquote>
  
  <p>I've been trying to tingle with the paremeters but I can't seem to figure out, why this happens. What would be the correct way to compute the glcm-matrix?</p>
  
  <h3>Update</h3>
  
  <p>The problem was in the grayscale conversion.
  The following changes were required:  </p>
  
  <pre class="lang-py prettyprint-override"><code>import numpy as np
  
  greyImg = np.array(img.convert('L', colors=8))
  </code></pre>