# Point cloud to height map in C++

With the increased popularity of 3D imaging and scanning I thought it would be easy to transform a xyz point cloud into a Height Map (xy matrix of z points), but after a couple of hours searching I found nothing. Maybe I'm looking in the wrong direction, isn't there some C++ library for this type of conversion?

• Welcome to scicomp! Could you give us a bit more information? In what format is your point cloud saved? Are they rastered in some form? What is the datatype you expect as output? Jan 28 at 11:14
• Thank you :-) The point cloud is generated and corrected for lens deformation so the points are no longer aligned in a grid, I get a vector of x, y, z points. The data type is double. I want to transform it into a matrix of xy size so that I can save it into an image like a height map. Jan 28 at 11:34
• I think your best bet is matlab, see (de.mathworks.com/matlabcentral/answers/…) or (de.mathworks.com/help/vision/…) Jan 28 at 12:06
• depending on the precision and rigorosity requirements, you may also get away with using functionalities of gnuplot or matplotlib to plot heatmaps. If I remember correctly both have the functionality to take non-grid data as input. see e.g. (stackoverflow.com/questions/2369492/…) Jan 28 at 12:10

Think of this as a point cloud over a chess board. Then, for each of the squares of the board, find all the points that lie over that square (i.e., whose $$x,y$$ values are within that square) and take the maximal $$z$$ value to generate the height over that square.

Of course, you're not bound to an $$8\times 8$$ board, but can choose the number of squares. You want to choose it in such a way that you have a sufficient number of points over each of the squares so that you get a reasonable approximation of the actual height, without "empty" squares.

• Its a possible solution, but I lose too much detail, I have 2000 by 2000 points and I want to keep the same number of points (resolution). Jan 28 at 16:04
• So I'm looking for some kind of interpolation of values. Jan 28 at 16:10
• Is your point cloud convex? In that case you could compute the convex hull. But if it's not convex, it's difficult to define exactly what the "upper surface" is unless you have a way to label which of the points are on the surface and which are in the interior. Jan 28 at 21:45
• The point cloud is not necessarily convex Jan 29 at 10:45
• So then how do you know what is an interior point and what is a point on the upper surface? Jan 29 at 20:38