基于Python的OpenCV学习
第七章、视觉直方图
00_思维导图
01_cv2.calcHist
import cv2
import matplotlib.pyplot as plt
img = cv2.imread('cat.jpg')
hist = cv2.calcHist([img],[0],None,[256],[0,256])
plt.figure(figsize=(32,16),dpi=40)
plt.plot(hist)
plt.xticks(fontsize=20)
plt.yticks(fontsize=20)
plt.show()
运行结果:
02_image.ravel
import cv2
import matplotlib.pyplot as plt
img = cv2.imread('cat.jpg')
plt.figure(figsize=(32,16),dpi=30)
plt.hist(img.ravel(),256)
plt.show()
03_cv2.equalizeHist
import cv2
import matplotlib.pyplot as plt
img1 = cv2.imread('cat.jpg',cv2.IMREAD_GRAYSCALE)
img2 = cv2.equalizeHist(img1)
plt.subplot(2,2,1),plt.imshow(img1)
plt.subplot(2,2,2),plt.imshow(img2)
plt.subplot(2,2,3),plt.hist(img1.ravel())
plt.subplot(2,2,4),plt.hist(img2.ravel())
plt.show()
运行结果: