#本质  统计每个像素灰度出现的概率
import cv2
import numpy as np
import matplotlib.pyplot as plt
img = cv2.imread('ruonan.jpg',1)
gray = cv2.cvtColor(img,cv2.COLOR_RGB2GRAY)
Info = gray.shape
height = Info[0]
width = Info[1]
count = np.zeros(256,np.float)
for i in range(0,height):
    for j in range(0,width):
        pixel = gray[i,j]
        index = int(pixel)
        count[index] = count[index]+1
for i in range(0,255):
    count[i] = count[i]/(height*width)
x = np.linspace(0,255,256)
y = count
plt.bar(x,y,0.9,alpha=1,color='b')#占比90%
plt.show()
cv2.waitKey(0)