How to do it...

Follow these steps:

  1. Import all necessary modules:
import cv2
import numpy as np
import matplotlib.pyplot as plt
  1. Load an image and display it:
grey = cv2.imread('../data/Lena.png', 0)
cv2.imshow('original grey', grey)
cv2.waitKey()
cv2.destroyAllWindows()
  1. Compute a histogram function:
hist, bins = np.histogram(grey, 256, [0, 255])
  1. Plot histogram and display it:
plt.fill(hist)
plt.xlabel('pixel value')
plt.show()