代码如下:

import cv2
import numpy as np
import matplotlib.pyplot as plt

img = cv2.imread('C:\\Users\\admin\\Desktop\\original_img3\\testimg\\messi.jpg')
_, _, colorChannel = img.shape
color = ['B', 'G', 'R']
plt.figure()
for i in range(colorChannel):
    hist_img, _ = np.histogram(img[:, :, i], 256)
    plt.plot(range(256), hist_img, label=color[i])
    plt.legend(loc='best')
    plt.title('histogram')

plt.figure()
for i in range(colorChannel):
    hist_img, _ = np.histogram(img[:, :, i], 256)
    cdf_img = np.cumsum(hist_img)   # accumulative histogram
    plt.plot(range(256), cdf_img, label=color[i])
    plt.legend(loc='best')
    plt.title('accumulative histogram')

效果如下:

 OpenCV-Python画直方图和累积直方图  OpenCV-Python画直方图和累积直方图

相关文章:

  • 2022-01-26
  • 2022-01-16
  • 2022-12-23
  • 2022-01-01
  • 2021-06-19
  • 2021-10-30
  • 2021-08-23
  • 2021-08-11
猜你喜欢
  • 2022-01-31
  • 2022-12-23
  • 2021-06-05
  • 2022-12-23
  • 2021-04-04
  • 2021-09-04
  • 2021-08-06
相关资源
相似解决方案