# 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? Commented Jan 28, 2021 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. Commented Jan 28, 2021 at 11:34
• I think your best bet is matlab, see (de.mathworks.com/matlabcentral/answers/…) or (de.mathworks.com/help/vision/…) Commented Jan 28, 2021 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/…) Commented Jan 28, 2021 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.