打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
彩色直方图(源码实现)
原理:和灰度直方图一样,只是将一个灰度通道换成了三个的RGB通道
import cv2
import numpy as np
import matplotlib.pyplot as plt
img = cv2.imread('D:/pythonob/imageinpaint/img/flower.jpg',1)
imgInfo = img.shape
height = imgInfo[0]
width = imgInfo[1]
count_b = np.zeros(256,np.float)
count_g = np.zeros(256,np.float)
count_r = np.zeros(256,np.float)
for i in range(0,height):
for j in range(0,width):
(b,g,r) = img[i,j]
index_b = int(b)
index_g = int(g)
index_r = int(r)
count_b[index_b] = count_b[index_b]+1
count_g[index_g] = count_g[index_g] + 1
count_r[index_r] = count_r[index_r] + 1
for i in range(0,256):
count_b[i] = count_b[i]/(height*width)
count_g[i] = count_g[i] / (height * width)
count_r[i] = count_r[i] / (height * width)
x = np.linspace(0,255,256)
y1 = count_b
y2 = count_g
y3 = count_r
plt.figure()
plt.bar(x,y1,0.9,alpha = 1 ,color = 'b')
plt.figure()
plt.bar(x,y2,0.9,alpha = 1 ,color = 'g')
plt.figure()
plt.bar(x,y3,0.9,alpha = 1 ,color = 'r')
plt.show()
cv2.waitKey(0)

效果图:

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Matplotlib数据可视化:柱状图与直方图
Python图像处理丨带你认识图像量化处理及局部马赛克特效
php 图片上传类
HTML代码实际应用讲解
phython+opencv图像处理
在 Google Colab 中使用 OpenCV 进行图像处理简介
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服