- OpenCV 3 Computer Vision with Python Cookbook
- Alexey Spizhevoy Aleksandr Rybnikov
- 56字
- 2021-08-27 19:47:43
How to do it...
Follow these steps:
- Import all necessary modules:
import cv2
import numpy as np
import matplotlib.pyplot as plt
- Load an image and display it:
grey = cv2.imread('../data/Lena.png', 0)
cv2.imshow('original grey', grey)
cv2.waitKey()
cv2.destroyAllWindows()
- Compute a histogram function:
hist, bins = np.histogram(grey, 256, [0, 255])
- Plot histogram and display it:
plt.fill(hist)
plt.xlabel('pixel value')
plt.show()