Can I convert a PointCloud to 2D Image?

I would like to convert the Pointcloud to a 2D image. Can that be done? In particular, I am trying to migrate the following matlab code?

pc = pcread(path);
img = double(pc.Color(:,:,1))

As I understand, I can see the xyz coordinates of the pointcloud in opend3d with the .points attribute and its associated color values with the .colors attribute. I however, do not understand how I can convert this information to a 2d Image. I think I need metadata information from the pointcloud such as the width and height of the image. For example, I know that a pcl I loaded contains 81920 points. If I knew the width and height of the point clouds, I think I could convert the point cloud to an image.

Does somebody have an idea how I can do that? I’m grateful for any hints and suggestions!

Does the point cloud come from a single scan of scanner like a kinect?

Thanks for your reply, @benjaminum ! Indeed, the point cloud comes from a single scanner.

Assuming that the scanner is image-based and there is a point for each pixel in your pointcloud you could simply do a reshape

img = np.asarray(pcd.colors).reshape(height, width, 3)

Of course you need to know the original image dimensions for that.

Thanks @benjaminum for the kind reply!

That is also what I did and it worked fine. However, the caveat is that I needed to know the original image dimension for this. In contrast, that doesn’t seem to be required in the matlab code I referenced above. Is there some related metadata information stored in the *.pcd files one could exploit?

Did you have a look at the .pcd header? I think this format stores width and height.

I did know the format of the image because I recorded them myself. However, I did not access the header file to read width and height. Do you know if that is possible at all with open3d, @benjaminum? I presume the metadata is read by the matlab function I referenced above so I wonder if I can do the same with open3d.

The height and width information is unfortunately not stored in the point cloud object by open3d.
You would need to parse this information separately.