问题描述
大家我正在尝试使用 python 将点云(X、Y、Z)转换为灰度图像.我了解到灰度图像可以由 Numpy 数组生成.但我现在拥有的是一组包含 X、Y 和高度的点.我想根据 X、Y 和灰度值(即高度)生成灰度图像.
EveryoneI'm trying to convert point cloud (X, Y, Z) to the grayscale image using python. I learned that the grayscale image could be generated by a Numpy array. But what I have now is a set of points which contains X, Y and height. I wanna generate a grayscale image based on X, Y and grayscale value which is Height.
有人可以给我一个想法吗?先谢谢了.
Can someone give me an idea about this?Thanks beforehand.
罗文
推荐答案
让我们假设 X、Y 已排列,因此它们将形成一个网格(这是构建矩形图像所必需的).从那里这很容易:
let's assume that the X,Y are arranged so they will form a grid (which is mandatory in order to build a rectangular image). from there this is easy:
import numpy as np
import matplotlib.pyplot as plt
# generate some data
ax = np.arange(-9, 10)
X, Y = np.meshgrid(ax, ax)
Z = X ** 2 + Y ** 2
# normalize the data and convert to uint8 (grayscale conventions)
zNorm = (Z - Z.min()) / (Z.max() - Z.min()) * 255
zNormUint8 = zNorm.astype(np.uint8)
# plot result
plt.figure()
plt.imshow(zNormUint8)
这篇关于将 XYZ 点云转换为灰度图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!