【发布时间】:2020-06-21 23:14:38
【问题描述】:
我试图从这样的图像创建一个直方图 1d
但我不知道该怎么做。有人可以帮帮我吗?
这是我的 HSV 直方图的简单代码:
from matplotlib import pyplot as plt
import cv2
image = cv2.imread('sample/sample4.jpg')
cv2.cvtColor(image, cv2.COLOR_RGB2HSV)
H, S, V = image[:,:,0],image[:,:,1],image[:,:,2]
plt.figure(figsize=(10,8))
plt.subplot(311) #plot in the first cell
plt.subplots_adjust(hspace=.5)
plt.title("Hue")
plt.hist(np.ndarray.flatten(H), bins=180)
plt.subplot(312) #plot in the second cell
plt.title("Saturation")
plt.hist(np.ndarray.flatten(S), bins=128)
plt.subplot(313) #plot in the third cell
plt.title("Luminosity Value")
plt.hist(np.ndarray.flatten(V), bins=128)
plt.show()
谢谢你的帮助
【问题讨论】:
-
要实现上图,需要将色调通道聚类成16个bin,确定每个bin的主色,然后计算每个主色出现的频率.计算整个图像的直方图不足以达到您想要的数字,因为您将绘制每个可能的色调值的出现频率。显示的图正在绘制图像中主要可见的内容。即便如此,您还必须考虑饱和度和价值,因此如果没有进一步的上下文,这个问题无法明确回答。
标签: python opencv matplotlib