灰度图像直方图(源码实现)

灰度图像直方图(源码实现),第1张

概述原理:统计每个像素灰度出现的概率 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]
原理:统计每个像素灰度出现的概率
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]
gray = cv2.cvtcolor(img,cv2.color_BGR2GRAY)
count = np.zeros(256,np.float)
for i in range(0,height):
for j in range(0,wIDth):
pixel = gray[i,j]
index = int(pixel)
count[index] = count[index]+1
for i in range(0,256):
count[i] = count[i]/(height*wIDth)
x = np.linspace(0,255,256)
y = count
plt.bar(x,y,0.9,Alpha = 1,color = ‘b‘)
plt.show()
cv2.waitKey(0)
效果图:

总结

以上是内存溢出为你收集整理的灰度图像直方图源码实现)全部内容,希望文章能够帮你解决灰度图像直方图(源码实现)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1191500.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-03
下一篇 2022-06-03

发表评论

登录后才能评论

评论列表(0条)

保存