title: histogram of gray scale values in numpy image
body: <p>I loaded an image into a numpy array and want to plot its color values in a histogram.</p>
  
  <pre><code>import numpy as np
  
  from skimage import io
  from skimage import color
  
  img = io.imread('img.jpg')
  img = color.rgb2gray(img)
  
  unq = np.unique(img)
  unq = np.sort(unq)
  </code></pre>
  
  <p>When we inspect the value of <code>unq</code> we will see something like</p>
  
  <pre><code>array([  5.65490196e-04,   8.33333333e-04,   1.13098039e-03, ...,
           7.07550980e-01,   7.09225490e-01,   7.10073725e-01])
  </code></pre>
  
  <p>which has still too much values for <code>matplotlib</code> so my idea was to loop over <code>unq</code> and remove every value which deviates only <code>x</code> from it's predecessor.</p>
  
  <pre><code>dels = []
  
  for i in range(1, len(unq)):
      if abs(unq[i]-unq[i-1]) &lt; 0.0003:
          dels.append(i)
  
  unq = np.delete(unq, dels)
  </code></pre>
  
  <p>Though this method works it is very inefficient as it does not uses numpy's optimized implementations.</p>
  
  <p><strong>Is there a numpy feature would could do this for me?</strong></p>
  
  <p><em>Just noticed that my algorithm looses information about how often a color occurs. Let me try to fix this</em>.</p>