我想测量16位图像中的像素强度。因此,我做了一个数值直方图,显示像素的数量相对于灰度值从0到65535 (16位)。我这样做了
hist= numpy.histogram(grayscaleimage.ravel(), 65536, [0, 65536])之后,我用(这意味着每个像素的像素数*像素值的总和)来测量图像的整体强度:
Intensity = 0
for i in range(len(hist[0])):
Intensity += hist[0][i]*hist[1][i]
print(Intesity)现在我想看看我的直方图。我不知道如何绘制hist,尽管我有我需要的值。有人能帮我一下吗?
发布于 2018-02-20 16:33:58
您可以直接使用matplotlib来执行以下操作:
import matplotlib.pyplot as plt
plt.hist(grayscaleimage.ravel(), bins=np.linspace(0, 65536, 1000))
plt.show() 或者像您已经做的那样使用numpy并绘制条形图。但是,您必须自己正确设置条形图的宽度,并跳过最后一个柱状图条目,使其具有与直方图相同的尺寸:
import numpy as np
import matplotlib.pyplot as plt
hist, bin_edges = np.histogram(grayscaleimage.ravel(), bins = np.linspace(0, 65536, 1000))
plt.bar(bin_edges[:-1], hist, width=65536./1000)
plt.show()我这里只用了1000个垃圾桶,但你也可以选择更多,这取决于你的图像的大小。
PS:如果你想要总强度,你不需要迭代所有的盒子。只需将图像np.sum(grayscaleimage)中的所有像素值相加,就可以得到更准确的结果。
https://stackoverflow.com/questions/48880363
复制相似问题