How to "fill in" a 2d grid based on neighbors

46 Views Asked by At

I've got an array of elevations on a plane, but there are missing values. Specifically it is elevations I derived from lunar satellite data regarding the south pole. I'd like to use the data to make a 1m x 1m x 1m terrain map but need a nice way to "fill" in any missing data in my array.

ex.. [[500, ??, ??, 517],[??, ??, 512, 514]]

I'd like to estimate / fill in the missing values programmatically, in a way that is even and consistent (even if not exactly precise).

Here is an example of my current array, coded to a PNG, with white level based on relative y value:

Lunar South Pole 89'S

I'm unaware of, but certain there is a relatively straight forward mathematic mutation that completes my matrix, but I'm totally unaware of the right things to search for. Bonus points if the solution is in Javascript, but a conversion is something I can hack if needed. :)

Further challenging is that data itself is actually pretty sparse as the 1m resolution desired isn't anywhere close to the beams of data that was collected. The top image was generated by compressing the known points by 1000. The actual data has elevation for some points, but most points are unknown, here is an uncompressed 100m x 100m square from right on the south pole (unknown data is colored magenta, while the little grey pixels are known altitudes):

Sparse Render