【发布时间】:2020-07-10 13:27:06
【问题描述】:
您好,我正在尝试按以下格式绘制颜色列表:
img = cv2.imread('./img/a.png')
ground = cv2.imread('./img/b.png')
descriptor = [img[ij] for ij in np.ndindex(ground.shape[:2]) if all(ground[ij])]
descriptor[0]
array([ 72, 70, 115], dtype=uint8)
我想得到这样的图表:
为了做到这一点,我使用以下方式的散点图:
fig = plt.figure()
axis = fig.add_subplot(1, 1, 1, projection="3d")
axis.scatter(descriptor[0],descriptor[0],descriptor[0], facecolors=descriptor, marker=".")
plt.show()
但我收到以下错误:
ValueError: 'c' argument must be a mpl color, a sequence of mpl colors 或数字序列,而不是 [array([ 72, 70, 115]
但如果我像这样更改颜色列表:
descriptor = [list(img[ij]) for ij in np.ndindex(ground.shape[:2]) if all(ground[ij])]
descriptor[0]
[ 72, 70, 115]
我收到此错误:
'c' 参数必须是 mpl 颜色、mpl 颜色序列或 数字序列,而不是 [[72, 70, 115], [71, 69, 114]
如何像图表一样绘制列表?
谢谢
a = [np.random.randint(10,240,3) for _ in range(20)]
descriptor = a
【问题讨论】:
-
你能提供一个
descriptor的最小例子吗?你想用它的位置作为颜色来绘制每一个? -
你可以在问题的顶部看到什么是描述符,是一个 len=3 numpy 数组的列表,我想使用描述符的每个值(描述符上的 3 个值)作为位置和颜色。
-
一个简短而完整的脚本可帮助人们快速调试并轻松确定适合您的答案。
-
descriptor[0]是 [x,y,z] 点吗? -
Descriptor[0] 是 [x,y,z] 位置和 [red, green, blue] 颜色
标签: python opencv matplotlib image-processing opencv-python