首页 > 编程语言 > 详细

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

时间:2019-11-09 13:08:06      阅读:262      评论:0      收藏:0      [点我收藏+]

代码如下:

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画直方图和累积直方图

原文:https://www.cnblogs.com/picassooo/p/11824972.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!