Saturday, November 7, 2015

Realtime Heightmap Generation using DCT's

OK this one has been the holy grail for me. Compressing data and then uncompressing data in realtime.

Well now I think it maybe possible with simplified DCT's. I am using the definition of DCT-II and DCT-III from Wikipedia. There are more accurate variations out there but this a good start for anyone wanting to know about DCT's

Here is the code:

Do you notice the >>2 at the end of each decoding? This is multiplying the DCT-III by 1 / √2N, in Wikipedia it says this step is optional but clearly it is completely necessary.
  
And here is the output:
I have skipped the quantize step because that is where the optimizations come from.
Notice the outputted values are within 15% of the values from the original. The chances of me guessing a number sequence within 15% of the original sequence is 1 * 10 ^ 18 or 1000000000000000000 to 1!

Here is a graph showing the space from 0 to 255 and the original values (red) vs. the computed values (blue). They are very close indeed.
The DCT is a wonder of the modern world!

By centering the data at 128 (subtracting 128 from each value) the results are amazing.
The results are almost perfect.

OK so k = 0,1,2,3,4,5,6,7. So what would happen if I was to use smaller 0.015625 increments. This turns 8 numbers into 512 numbers. Massive amount of compression.
The output is very impressive exactly what I was hoping for.
So now using this code you can convert Google Earth Elevations into 8 numbers! Exactly what I wanted.

No comments:

Post a Comment