Python编程-计算图像直方图
来源:互联网 发布:手机网游破解软件 编辑:程序博客网 时间:2024/06/02 02:54
灰度直方图:反映的是一幅图像中各灰度级像素出现的频率。以灰度级为横坐标,纵坐标为灰度级的频率(或各灰度级的个数),绘制而成的关系图就是灰度直方图。它是图像的一个重要特征,反映了图像灰度分布的情况,同时也是直方图均衡化的基础。
频率的计算式为
直方图的计算:
该图像像元总数 为8 * 8 = 64 , i = [0,7] v0 = 5 / 64 v1 = 12 / 64 v2 = 18 / 64 v3 = 8 / 64 v4 = 1 / 64 v5 = 5 /64 v6 = 8 / 64 v7 = 5 /64
Python代码实现:
该篇文章仅是本人做实验的的结果,代码的执行效率可能不高,比不上pylab中封装好的hist(),欢迎广大在图像处理或计算机视觉上有兴趣的网友提出好的优化算法。
from PIL import Imagefrom numpy import *import matplotlib.pyplot as pltdef calHist(path): #open the image and convert to grayscale #transform it into array img = array(Image.open(path).convert("L")) m = img.shape[0]#get the number of row n = img.shape[1]#get the number of column l = m * n img = img.reshape(l)#adjust img to one dimension histo = zeros(256)#create a matrix with all of 0 histo = histo.reshape(256) for value in range(256): for i in img: if i == value: histo[value] = histo[value] + 1 #histo = histo / l return histodef drawHist(myList,Title,xLabel,yLabel,xMin,xMax,yMin,yMax): plt.hist(myList,256) plt.xlabel(xLabel) plt.xlim(xMin,xMax) plt.ylabel(yLabel) plt.ylim(yMin,yMax) plt.title(Title) plt.show()
声明:本人第一次写博客,有一些文字内容参考了网上一些文档或PPT。博客的版面设计弄得不好看,请多见谅!
阅读全文
0 0
- Python编程-计算图像直方图
- OpenCV2编程手册笔记之 4.2计算图像的直方图
- python 图像直方图处理
- 图像处理之直方图计算
- calcHist()计算图像直方图opencv
- OpenCV之图像直方图计算
- Python 显示图像的直方图
- 实现图像轮廓和图像直方图(Python)
- 数学之路-python计算实战(14)-机器视觉-图像增强(直方图均衡化)
- OpenCV2编程手册笔记之 4.2计算图像的直方图(彩色)
- 灰度直方图计算 直方图相似性度量 图像分块
- opencv2学习笔记:4.2计算图像直方图
- 计算彩色的BGR图像的直方图
- OpenCV 计算图像一维直方图
- 计算灰度图像的归一化直方图
- OpenCV【4】---calcHist 计算图像的直方图
- OpenCV 学习(计算图像的直方图)
- Opencv---计算图像直方图方差和均值
- DigiDNA iMazing For Windows(苹果IOS设备管理软件)官方中文破解版V2.3.8下载 | imazing激活码
- tomcat启动报错org.apache.catalina.deploy.WebXml addFilter
- ACdreamXMUT新生摸底训练赛C
- Linux下开发-wait和waitpid
- “耳鸣”自己在家也可以治疗
- Python编程-计算图像直方图
- 1>MSVCRTD.lib(crtexew.obj) : error LNK2019: 无法解析的外部符号 WinMain
- 【UnityShader入门精要】Unityshader中的漫反射(逐顶点漫反射diffuse)
- VS2017的功能探索
- Json 从后端发送到前端 Easyui
- 快速读入
- Android的数据存储方式---内部存储与外部存储
- 01.nexus的安装和使用
- 项目中Classpath路径