直方图-统计直方图

统计每个灰度值对应的个数,计算结果是256行一列的数组
直方图-统计直方图_第1张图片
image:使用【】括起来使用
channels: 使用【】括起来使用

  • 灰度图像 0
  • 彩色图像 0 1 2 分别对应通道B G R

mask:

  • 统计整幅图片 None
  • 统计图片某一部分的直方图,需要掩码图片。后续介绍。

hietSize:一般256,使用【】括起来使用
ranges:一般【0,255】
accumulate:可以计算一张图片的直方图,也可以计算一组图片的直方图,可以省略不写。
直方图-统计直方图_第2张图片

import cv2
import numpy as np
o=cv2.imread('image\\boat.bmp')
hist=cv2.calcHist([o],[0],None,[256],[0,255])     #不要忘记中括号
print(hist)
print(type(hist))        #类型
print(hist.size)         #大小
print(hist.shape)        #形状

类型 :数组类型
大小:256个数
形状:256行 1列
直方图-统计直方图_第3张图片

运算结果详情:

D:\Users\sunny\Anaconda3\python.exe "F:/Pycharm Project/hello world.py"
[[  1.00000000e+00]
 [  0.00000000e+00]
 [  0.00000000e+00]
 [  0.00000000e+00]
 [  0.00000000e+00]
 [  0.00000000e+00]
 [  0.00000000e+00]
 [  1.00000000e+00]
 [  0.00000000e+00]
 [  0.00000000e+00]
 [  1.00000000e+00]
 [  1.00000000e+00]
 [  2.00000000e+00]
 [  1.30000000e+01]
 [  7.00000000e+00]
 [  6.00000000e+01]
 [  1.66000000e+02]
 [  4.13000000e+02]
 [  6.96000000e+02]
 [  9.45000000e+02]
 [  9.39000000e+02]
 [  7.78000000e+02]
 [  8.22000000e+02]
 [  8.76000000e+02]
 [  8.35000000e+02]
 [  9.40000000e+02]
 [  1.14600000e+03]
 [  1.25500000e+03]
 [  1.26600000e+03]
 [  1.24800000e+03]
 [  1.35900000e+03]
 [  1.47800000e+03]
 [  1.36500000e+03]
 [  1.38300000e+03]
 [  1.43200000e+03]
 [  1.48100000e+03]
 [  1.30500000e+03]
 [  1.29700000e+03]
 [  1.23400000e+03]
 [  1.34400000e+03]
 [  1.12200000e+03]
 [  1.10600000e+03]
 [  1.13100000e+03]
 [  1.11200000e+03]
 [  9.65000000e+02]
 [  9.77000000e+02]
 [  9.52000000e+02]
 [  9.28000000e+02]
 [  8.33000000e+02]
 [  6.80000000e+02]
 [  6.26000000e+02]
 [  6.04000000e+02]
 [  5.86000000e+02]
 [  5.20000000e+02]
 [  4.80000000e+02]
 [  5.17000000e+02]
 [  5.31000000e+02]
 [  4.47000000e+02]
 [  4.41000000e+02]
 [  4.91000000e+02]
 [  4.97000000e+02]
 [  4.44000000e+02]
 [  5.07000000e+02]
 [  5.25000000e+02]
 [  5.69000000e+02]
 [  5.33000000e+02]
 [  5.04000000e+02]
 [  5.39000000e+02]
 [  5.34000000e+02]
 [  5.15000000e+02]
 [  4.72000000e+02]
 [  4.76000000e+02]
 [  5.07000000e+02]
 [  4.63000000e+02]
 [  4.83000000e+02]
 [  4.92000000e+02]
 [  4.96000000e+02]
 [  4.90000000e+02]
 [  4.52000000e+02]
 [  4.47000000e+02]
 [  4.39000000e+02]
 [  4.63000000e+02]
 [  4.46000000e+02]
 [  4.67000000e+02]
 [  4.65000000e+02]
 [  4.99000000e+02]
 [  4.51000000e+02]
 [  4.82000000e+02]
 [  4.55000000e+02]
 [  4.91000000e+02]
 [  4.91000000e+02]
 [  4.67000000e+02]
 [  5.19000000e+02]
 [  4.81000000e+02]
 [  4.47000000e+02]
 [  5.10000000e+02]
 [  4.93000000e+02]
 [  5.18000000e+02]
 [  5.00000000e+02]
 [  4.90000000e+02]
 [  5.26000000e+02]
 [  5.11000000e+02]
 [  5.47000000e+02]
 [  5.26000000e+02]
 [  5.73000000e+02]
 [  5.98000000e+02]
 [  5.52000000e+02]
 [  5.78000000e+02]
 [  5.66000000e+02]
 [  5.77000000e+02]
 [  6.04000000e+02]
 [  5.47000000e+02]
 [  6.11000000e+02]
 [  6.66000000e+02]
 [  6.08000000e+02]
 [  6.17000000e+02]
 [  6.05000000e+02]
 [  6.08000000e+02]
 [  6.46000000e+02]
 [  6.59000000e+02]
 [  6.14000000e+02]
 [  7.25000000e+02]
 [  7.35000000e+02]
 [  7.11000000e+02]
 [  6.65000000e+02]
 [  7.34000000e+02]
 [  7.84000000e+02]
 [  8.06000000e+02]
 [  7.86000000e+02]
 [  8.71000000e+02]
 [  9.10000000e+02]
 [  9.21000000e+02]
 [  1.02900000e+03]
 [  9.63000000e+02]
 [  1.12000000e+03]
 [  1.13100000e+03]
 [  1.13300000e+03]
 [  1.23200000e+03]
 [  1.46200000e+03]
 [  1.46600000e+03]
 [  1.37200000e+03]
 [  1.49500000e+03]
 [  1.68600000e+03]
 [  1.69900000e+03]
 [  1.64200000e+03]
 [  1.62100000e+03]
 [  1.79800000e+03]
 [  1.84000000e+03]
 [  1.81700000e+03]
 [  1.82700000e+03]
 [  1.89000000e+03]
 [  2.06400000e+03]
 [  1.99600000e+03]
 [  2.17400000e+03]
 [  2.32700000e+03]
 [  2.64700000e+03]
 [  2.77400000e+03]
 [  3.39400000e+03]
 [  4.17800000e+03]
 [  5.15200000e+03]
 [  4.75500000e+03]
 [  4.56700000e+03]
 [  4.26800000e+03]
 [  4.46500000e+03]
 [  3.97100000e+03]
 [  4.03400000e+03]
 [  4.09600000e+03]
 [  4.74500000e+03]
 [  4.55500000e+03]
 [  4.80800000e+03]
 [  4.78200000e+03]
 [  5.39400000e+03]
 [  4.92700000e+03]
 [  4.66400000e+03]
 [  4.32200000e+03]
 [  4.75600000e+03]
 [  4.53500000e+03]
 [  4.37400000e+03]
 [  4.16300000e+03]
 [  4.36700000e+03]
 [  3.75900000e+03]
 [  3.18400000e+03]
 [  2.76400000e+03]
 [  2.42300000e+03]
 [  2.18300000e+03]
 [  1.85100000e+03]
 [  1.77500000e+03]
 [  1.72400000e+03]
 [  1.50700000e+03]
 [  1.22500000e+03]
 [  9.16000000e+02]
 [  7.45000000e+02]
 [  6.53000000e+02]
 [  5.31000000e+02]
 [  4.25000000e+02]
 [  8.24000000e+02]
 [  0.00000000e+00]
 [  3.44000000e+02]
 [  3.44000000e+02]
 [  3.34000000e+02]
 [  3.72000000e+02]
 [  3.15000000e+02]
 [  3.29000000e+02]
 [  6.66000000e+02]
 [  0.00000000e+00]
 [  6.76000000e+02]
 [  0.00000000e+00]
 [  3.53000000e+02]
 [  3.85000000e+02]
 [  3.91000000e+02]
 [  3.78000000e+02]
 [  3.98000000e+02]
 [  4.39000000e+02]
 [  4.26000000e+02]
 [  3.74000000e+02]
 [  3.62000000e+02]
 [  3.35000000e+02]
 [  3.03000000e+02]
 [  2.39000000e+02]
 [  1.84000000e+02]
 [  1.52000000e+02]
 [  1.00000000e+02]
 [  7.10000000e+01]
 [  5.30000000e+01]
 [  6.10000000e+01]
 [  4.40000000e+01]
 [  3.40000000e+01]
 [  2.60000000e+01]
 [  2.20000000e+01]
 [  1.00000000e+01]
 [  7.00000000e+00]
 [  3.00000000e+00]
 [  2.00000000e+00]
 [  0.00000000e+00]
 [  0.00000000e+00]
 [  1.00000000e+00]
 [  0.00000000e+00]
 [  0.00000000e+00]
 [  0.00000000e+00]
 [  1.00000000e+00]
 [  0.00000000e+00]
 [  0.00000000e+00]
 [  0.00000000e+00]
 [  0.00000000e+00]
 [  0.00000000e+00]
 [  0.00000000e+00]
 [  0.00000000e+00]
 [  0.00000000e+00]
 [  0.00000000e+00]
 [  0.00000000e+00]
 [  0.00000000e+00]
 [  0.00000000e+00]
 [  0.00000000e+00]
 [  0.00000000e+00]
 [  0.00000000e+00]
 [  0.00000000e+00]]

256
(256, 1)

你可能感兴趣的:(python-OpenCV)