Heightmap generation algorithm?

chakrit picture chakrit · Feb 17, 2009 · Viewed 7.5k times · Source

I was looking around the internet and couldn't find a perfect algorithm for this particular problem:

Our customer have a set of points and weight data along with each point as can be demonstrated by this image:

weighted points http://chakrit.net/files/stackoverflow/so_heightmap_points.png

Of which, we have a GIS program that could generate a "heightmap" or a sort of terrain data from these points and their weight values but as we have near a thousand points of data and that these will change over time, we would like to create our own tools to auto-generate these heightmaps.

So far, I've tried to calculate the weight for each pixel from its distance to the closest data point with Sqrt((x1 - x2) ^ 2 + (y1 - y2) ^ 2) and applying weight and distance factor to the data point's color to produce the resulting gradient color for that particular pixel:

heightmap result http://chakrit.net/files/stackoverflow/so_heightmap_result.png

You can see that there are still problems with certain configuration of data points and the algorithm sometimes produce a rather polygonal image when there is a lot of data points. The ideal result should looks more like an ellipsis and less like a polygon.

Here is one example image from wikipedia article on gradient ascent which demonstrates the result I want:

mountains http://chakrit.net/files/stackoverflow/so_gradient_descent.png

The gradient ascent algorithm is not of my interest. What I'm interested in; is the algorithm to calculate the original function in that picture in the first place, provided data points with weights.

I've not taken any class in topological maths, but I can do some calculus. I think I may be missing something and am rather lost at what should I type in that Google search box.

I need some pointers.

Thanks!

Answer

ShuggyCoUk picture ShuggyCoUk · Feb 17, 2009

What you are looking for is Surface Interpolation.

Some products exist to do this (here's one)

The resulting function/spline/other mathematical construct can then be interrogated at the required resolution to supply the height map.

Your interpolation function

Sqrt((x1 - x2) ^ 2 + (y1 - y2) ^ 2) 

Is similar to Inverse Distance Weighted methods except you are applying an arbitrary filter and discarding many of the other data points.

Most of these techniques rely on a reasonable number of samples and 'terrain-like' behaviour underpinning the values.

I suggest using the weight as the height sample and trying the simple Shepard's Method in the second link (do not filter any pixels to start with) by taking the proportion of a sample points contribution to the overall height value at an interpolation point you can blend the colours of the samples in those ratios to also colour the point. Use the intensity (roughly speaking the grayscale in simple RGB space) to display the height or add contour lines in black like the example image does.