1 #!/bin/python3
2
3 import cv2 as cv
4 import numpy as np
5 from matplotlib import pyplot as plt
6
7
8 def plot_demo(image):
9 plt.hist(image.ravel(),256,[0,255])
10 plt.show("直方图")
11
12 def image_hist(image):
13 color = ('blue','green','red')
14 for i,color in enumerate(color):
15 hist = cv.calcHist([image],[i],None,[256],[0,256])
16 plt.plot(hist,color=color)
17 plt.xlim([0,256])
18 plt.show()
19
20
21 print("----------Hello Python-----------------")
22 src = cv.imread("/home/laohe/downloads/image.jpeg")
23 cv.namedWindow("input image",cv.WINDOW_AUTOSIZE)
24 cv.imshow("input image",src)
25 #plot_demo(src)
26 image_hist(src)
27
28 cv.waitKey(0)
29
30 cv.destroyAllWindows()
~