简体   繁体   English

我应该如何在 python 中绘制 XYZ 数据点以在 RGB 中创建深度图像

[英]How should I plot XYZ data points to create a depth image in RGB in python

I am working on a small project where I am given a 2D array of XYZ data.我正在做一个小项目,在那里我得到了一个 XYZ 数据的二维数组。 Something in this manner:这种方式的东西:

a = [[1,7,13,3,4],
     [6,21,32,11,2]]

where x represents the column of the array, y represents the row of the array, and z represents the content of the array, which is the distance.其中x代表数组的列,y代表数组的行,z代表数组的内容,即距离。 What I am trying to accomplish is to use the 2d array and plot a depth image in RGB.我想要完成的是使用二维数组并在 RGB 中绘制深度图像。 To elaborate, the closer the distance (z) value, I want the point to be plotted as red.详细说明,距离 (z) 值越近,我希望将点绘制为红色。 And as the distance (z) values increase, I want to plot it yellow, green or blue depending on how large the distance is.随着距离 (z) 值的增加,我想根据距离的大小将其绘制为黄色、绿色或蓝色。

I added a sample picture for better clarification.我添加了一个示例图片以便更好地说明。
深度图像

I am trying to accomplish this in python.我正在尝试在 python 中完成此操作。 I tried researching into it, but most of the time I found how to extract XYZ data from a depth image or from a point cloud, instead of using XYZ data to plot a depth image.我尝试研究它,但大多数时候我发现如何从深度图像或点云中提取 XYZ 数据,而不是使用 XYZ 数据来绘制深度图像。

Please let me know if this is possible or what python libraries are available to achieve this.请让我知道这是否可行,或者有哪些 Python 库可以实现这一点。

Thank you.谢谢你。

EDIT: I believe it might help noting that the 2D array consists of point cloud data generated by a rangefinder sensor.编辑:我相信注意到二维阵列由测距仪传感器生成的点云数据可能会有所帮助。 I want to be able to construct a still 2d image of the scanned area using the data points.我希望能够使用数据点构建扫描区域的静止二维图像。 I also want to make use of colormaps in order to allow me to visualize the depth of the image.我还想利用颜色图来可视化图像的深度。

Here's an example using seaborn :这是一个使用seaborn的示例:

Generating sample data:生成样本数据:

def func(x, y):
    return np.exp(-x**2-y**2)

xaxis = np.linspace(-1, 1, 100)
yaxis = np.linspace(-1, 1, 200)
result = func(xaxis[:,None], yaxis[None,:])

Plotting:绘图:

sns.heatmap(result, cmap=sns.color_palette("Spectral_r", as_cmap=True))
plt.yticks([],[])
plt.xticks([],[])

Result:结果: 在此处输入图片说明

something along the lines of this?类似的东西?

from matplotlib.pylab import plt
a = [[1,7,13,3,4],
     [6,21,32,11,2]]
plt.matshow(a, cmap=plt.cm.viridis)
plt.colorbar()

在此处输入图片说明

You can pass large arrays such as images.您可以传递大型数组,例如图像。 Here I use an example image from matplotlib, I clip the colors to get a (120, 560) and not a (120, 560, 3) array and I display it:在这里,我使用来自 matplotlib 的示例图像,我剪裁了颜色以获得 (120, 560) 而不是 (120, 560, 3) 数组并显示它:

from matplotlib.pylab import plt
from matplotlib.cbook import get_sample_data
fn = get_sample_data("logo2.png", asfileobj=False)
img = plt.imread(fn, format='png')[...,0] #get single color channel
plt.matshow(img,cmap=plt.cm.jet,interpolation='bicubic')#see imshow for more arguments
plt.colorbar()

在此处输入图片说明

If I am not mistaken plt.matshow is a subclass of plt.imshow如果我没记错的话 plt.matshow 是 plt.imshow 的子类

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM