I mapped the pixels from metres to the range 0..1, but I had to estimate the maximum value. I managed to successfully save the image after doing this. However there seem to be issues when loading.
I'm loading the image in and printing the pixel values, however it segfaults after a bit.