title: Python - Calculate histogram of image
body: <p>I'm working on teaching myself the basics of computerized image processing, and I am teaching myself Python at the same time.</p>
  
  <p>Given an image <code>x</code> of dimensions 2048x1354 with 3 channels, efficiently calculate the histogram of the pixel intensities.  </p>
  
  <pre><code>import numpy as np, cv2 as cv
  
  img = cv.imread("image.jpg")
  bins = np.zeros(256, np.int32)
  
  for i in range(0, img.shape[0]):
      for j in range(0, img.shape[1]):
  
          intensity = 0
          for k in range(0, len(img[i][j])):
              intensity += img[i][j][k]
  
          bins[intensity/3] += 1
  
  print bins
  </code></pre>
  
  <p>My issue is that this code runs pretty slowly, as in ~30 seconds.  How can I speed this up and be more Pythonic?</p>