patternMinor
Algorithm for generating heat maps
Viewed 0 times
mapsalgorithmgeneratingforheat
Problem
I am looking to generate a heat map from some data. I have a value and a location (longitude and latitude). I understand generating a colour from the value, however I'm not sure how I would go about generating the matrix to use for this.
I figure it's best to place the location points into buckets essentially (so that I have the same number of buckets as pixels in my map) but I'm not sure how to calculate the values for the buckets where I don't have any readings.
Has anyone got any experience with this?
Thanks!
I figure it's best to place the location points into buckets essentially (so that I have the same number of buckets as pixels in my map) but I'm not sure how to calculate the values for the buckets where I don't have any readings.
Has anyone got any experience with this?
Thanks!
Solution
You have to interpolate the missing heat values. There's some mathematics that explains this pretty well (man, it's been a while) but, if I recall correctly, the correct physical way to do this (assuming no heat sources in the area being interpolated) is the following:
To be safe, you should probably double-buffer this process, so that while doing the first step, changing the value of the first pixel doesn't affect the value for the second pixel. Example:
Already the values are beginning to settle down a bit. This is easy and fast to automate, though naturally, you'll only get an approximation. See here and here for more information on the physics and mathematics behind this (and whether this is even applicable to your situation!!!)
- For each pixel for which there wasn't original data, assign the value of the pixel to the average value of all surrounding pixels.
- Repeat (1) until no pixel changes its value by at least some $\epsilon$
To be safe, you should probably double-buffer this process, so that while doing the first step, changing the value of the first pixel doesn't affect the value for the second pixel. Example:
5.0 4.0 4.0 3.0 5.0 4.0 4.0 3.0 5.0 4.0 4.0 3.0 5.0 4.0 4.0 3.0
2.0 --- --- 1.0 2.0 3.0 2.5 1.0 2.0 2.6 2.6 1.0 2.0 2.8 2.5 1.0
1.0 --- --- 3.0 => 1.0 2.0 2.5 3.0 => 1.0 2.4 2.4 3.0 => 1.0 2.3 2.5 3.0
3.0 3.0 2.0 4.0 3.0 3.0 2.0 4.0 3.0 3.0 2.0 4.0 3.0 3.0 2.0 4.0
=> 5.0 4.0 4.0 3.0
2.0 2.7 2.6 1.0
1.0 2.3 2.5 3.0 ...
3.0 3.0 2.0 4.0Already the values are beginning to settle down a bit. This is easy and fast to automate, though naturally, you'll only get an approximation. See here and here for more information on the physics and mathematics behind this (and whether this is even applicable to your situation!!!)
Code Snippets
5.0 4.0 4.0 3.0 5.0 4.0 4.0 3.0 5.0 4.0 4.0 3.0 5.0 4.0 4.0 3.0
2.0 --- --- 1.0 2.0 3.0 2.5 1.0 2.0 2.6 2.6 1.0 2.0 2.8 2.5 1.0
1.0 --- --- 3.0 => 1.0 2.0 2.5 3.0 => 1.0 2.4 2.4 3.0 => 1.0 2.3 2.5 3.0
3.0 3.0 2.0 4.0 3.0 3.0 2.0 4.0 3.0 3.0 2.0 4.0 3.0 3.0 2.0 4.0
=> 5.0 4.0 4.0 3.0
2.0 2.7 2.6 1.0
1.0 2.3 2.5 3.0 ...
3.0 3.0 2.0 4.0Context
StackExchange Computer Science Q#10178, answer score: 4
Revisions (0)
No revisions yet.