OpenCV---如何统计图像的像素分布值个数(6)

代码如下:
import cv2 as cv
import matplotlib.pyplot as plt
import numpy as np
def statistics():
    src = cv.imread("D:/matplotlib/0.jpg")
    cv.imshow("q",src)
    h,w,ch = np.shape(src)
    gray = cv.cvtColor(src,cv.COLOR_BGR2GRAY)
    cv.imshow("gray",gray)
    hest = np.zeros([256],dtype = np.int32)
    for row in range(h):
        for col in range(w):
            pv = gray[row,col]
            hest[pv] +=1
    plt.plot(hest,color = "r")
    plt.xlim([0,256])
    plt.show()
    cv.waitKey(0)
    cv.destroyAllWindows()
statistics()

运行效果:

OpenCV---如何统计图像的像素分布值个数(6)_第1张图片

你可能感兴趣的:(OpenCV)