import cv2 as cv
import numpy as np
from matplotlib import pyplot as plt
def plot_demo(image):
plt.hist(image.ravel(), 256, [0, 256])#统计频次
plt.show("直方图")
def image_hist(image):
color = ('blue', 'green', 'red')
for i, color in enumerate(color):
hist1 = cv.calcHist([image], [i], None, [256], [0, 256])
plt.plot(hist1, color=color)
plt.xlim([0, 256])
plt.show()
src = cv.imread("1.jpg")
cv.namedWindow("input image", cv.WINDOW_AUTOSIZE)
cv.imshow("input image", src)
plot_demo(src)
image_hist(src)
cv.waitKey(0)
cv.destroyAllWindows()
python+openCV图像处理(十二)直方图
最新推荐文章于 2021-11-24 00:17:06 发布