如何在OpenCV中绘制图像的3D直方图 [英] How to plot 3D histogram of an image in OpenCV

查看:98
本文介绍了如何在OpenCV中绘制图像的3D直方图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

[更新]我找到了更多示例,我现在就可以这样做 我知道这个问题已经问了,我尝试这个

I know this question is already ask and i try this How to calculate 3D histogram in python using open CV but it doesn't work

我想要这样的内容 3D直方图

这就是我现在所拥有的我的图表

this is what i have now My Graph

hsv_image = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
h,s,v = cv2.split(hsv_image)

fig = plt.figure(figsize=(8,7))
ax = plt.axes(projection='3d'), plt.title("Histogram 3D")
plt.hist(h.ravel(), 256, [0, 256])
plt.hist(s.ravel(), 256, [0, 256])
plt.hist(v.ravel(), 256, [0, 256])

我可以只使用plt.hist()绘制3d条形图还是需要更多内容?

can i use just plt.hist() to plot 3d bar or I need something more?

我一直在搜索图像教程的3d直方图,但是我找不到任何

i have been searching for 3d histogram of an image tutorial but i can't find any

推荐答案

这是我的结果:

代码:

#!/usr/bin/python3
# 2017.12.20 14:00:12 CST
# 2017.12.20 14:26:08 CST

from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
import cv2

img = cv2.imread("panda.png")
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
h,s,v = cv2.split(hsv)
fig = plt.figure()

ax = fig.add_subplot(111, projection='3d')
for x, c, z in zip([h,s,v], ['r', 'g', 'b'], [30, 20, 10]):
    xs = np.arange(256)
    ys = cv2.calcHist([x], [0], None, [256], [0,256])
    cs = [c] * len(xs)
    cs[0] = 'c'
    ax.bar(xs, ys.ravel(), zs=z, zdir='y', color=cs, alpha=0.8)

ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
plt.show()

这篇关于如何在OpenCV中绘制图像的3D直方图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆