[英]Converting 2D depth image/heatmap to 3D height field?
I was wondering how to convert a 2D depth image/heatmap to a 3D height field.我想知道如何将 2D 深度图像/热图转换为 3D 高度场。 Where the Z values are the values of the 2D image.
其中 Z 值是 2D 图像的值。
I have an RGB image:我有一个 RGB 图像:
I also have a corresponding depth image/heatmap:我也有相应的深度图像/热图:
I would like to combine them into a height field like this, where the Z values are the values of the depth image/heatmap:我想将它们组合成这样的高度场,其中 Z 值是深度图像/热图的值:
Except keeping the RGB values from the RGB image in the 3D heightfield.除了在 3D 高度场中保留来自 RGB 图像的 RGB 值。
What you are describing is essentially adding another dimension to the dataset.您所描述的本质上是向数据集添加另一个维度。 There are a few ways to achieve that, but note that some ways might be confusing to other people.
有几种方法可以实现这一点,但请注意,有些方法可能会让其他人感到困惑。 The other program you are exporting to might also have strong expectations of the data's shape, etc, so check that.
您要导出到的其他程序也可能对数据的形状等有强烈的期望,所以请检查一下。 What follows is just some thoughts about what you're trying to do...
接下来是关于你正在尝试做的事情的一些想法......
Essentially, you're describing having 2 'attributes' of the data: the colour image (a 3-channel attribute), and the height field (a single 'channel').本质上,您描述的是具有 2 个数据“属性”:彩色图像(3 通道属性)和高度字段(单个“通道”)。 Some options:
一些选项:
h5py
.h5py
将它们都放入 HDF5 文件中。 This format is essentially like a little file system, with nested 'folders', and it allows for an arbitrary amount of documentation and metadata.xarray
.xarray
。 This is basically n-dimensional pandas
and would let you store the two arrays in a single data structure.pandas
并且可以让您将两个 arrays 存储在单个数据结构中。 It's not ideal for this use case, but it does at least let you label the axes, so you can be clear about what the 4 'channels' are.class
for your data.class
。 This way you can document exactly what the two arrays are, and write methods to do things like plot them together. Here's how the class might look:以下是 class 的外观:
class BumpImage():
"""
An image with a 3d height field attached.
"""
def __init__(self, photo, height):
if photo.ndim == 2:
# Make greyscale image into RGB.
photo = np.repeat(photo[:, :, None], 3, axis=-1)
self.photo = photo
if height.shape == photo.shape[:2]:
self.height = height
else:
raise TypeError("Height must be 2d array")
def size(self):
return self.height.shape
def plot(self, ax=None):
# Make a 3d plot with matplotlib or whatever.
return ax
def save(self, fname):
# Make HDF5 file called fname.
return
Things I would not do:我不会做的事情:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.