title: Create Image Histogram Manually and Efficiently in Python
body: <p>I want to write codes that can show the histogram of an image without using built in Matplotlib hist function.</p>
  
  <p>Here is my codes:</p>
  
  <pre><code>import cv2 as cv
  import numpy as np
  from matplotlib import pyplot as plt
  
  def manHist(img):
     row, col = img.shape # img is a grayscale image
     y = np.zeros((256), np.uint64)
     for i in range(0,row):
        for j in range(0,col):
           y[img[i,j]] += 1
     x = np.arange(0,256)
     plt.bar(x,y,color="gray",align="center")
     plt.show()
  
  def main():
     img = cv.imread("C:/Users/Kadek/Documents/MATLAB/2GS.jpg")
     manHist(img)
  
  main()
  </code></pre>
  
  <p>My question is, is there a more efficent way to make an array of pixel value frequency without using for loop?</p>