飞桨 图像直方图统计

统计的图像中像素灰度值

计算机领域中,灰度(Gray scale)数字图像是每个像素只有一个采样颜色的图像。

代码展示:

import cv2
from matplotlib import pyplot as pyplot

img = cv2.imread('data/data131367/微信图片_20220308140220.jpg', 1)   
 #收集到的数据只考虑灰度值所以为1

#采用直方图的形式输出
pyplot.hist(img.reshape([-1]), 256, [0, 256])
pyplot.show()
#采用折线图的形式输出
import cv2
from matplotlib import pyplot as pyplot

img = cv2.imread('data/data131367/微信图片_20220308140220.jpg',1)
#收集到的数据只考虑灰度值所以为1

color = ('r', 'g', 'b')
for i, col in enumerate(color):
    histr = cv2.calcHist([img], [i], None, [256], [0,256])
    pyplot.plot(histr, col)
    pyplot.xlim([0,256])

pyplot.show()

cv2.calcHist解释:

def calcHist(images: Any,
             channels: Any,
             mask: Any,
             histSize: Any,
             ranges: Any,
             hist: Any = None,
             accumulate: Any = None) -> Non

enumerate python官网解释: 

enumerate(iterablestart=0)

Return an enumerate object. iterable must be a sequence, an iterator, or some other object which supports iteration. The __next__() method of the iterator returned by enumerate() returns a tuple containing a count (from start which defaults to 0) and the values obtained from iterating over iterable.

>>>

应用实例:

>>> seasons = ['Spring', 'Summer', 'Fall', 'Winter']
>>> list(enumerate(seasons))
[(0, 'Spring'), (1, 'Summer'), (2, 'Fall'), (3, 'Winter')]
>>> list(enumerate(seasons, start=1))
[(1, 'Spring'), (2, 'Summer'), (3, 'Fall'), (4, 'Winter')]
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值