# Which algorithms are usable for heatmaps and what are their pros and cons

This is a cross post from Stack Overflow, and DSP at Stackexchange since I cannot really decide which part of Stackexchange is most fitting. If this is the wrong place please tell me and I'll remove the question.

I have a matrix with numerical data. The matrix contains values from 0 to an arbitrary integer value.

Each element of the matrix is equivalent to a coordinate on a map.

I want to display that data as a heatmap overlayed the original map.

The three approaches I have found so far are

1. Linear interpolation. I guess the interpolation is don from the original datapoint to some set distance away from it in each direction.

2. Average of surrounding cells. Each empty cell gets the average value of the eight adjacent cells.

3. Gaussian blur as suggested on the SO thread.

4. Box blur with 1..n passes.

Are there any more methods? What are the pros and cons of the different approaches? What is a good source, online or print, for a discussion on heatmaps or similar problems?

• A problem is image resampling. Other types of interpolation/filtering take larger amounts of surrounding data into account, and using different algorithms to combine them. See Bicubic interpolation; the 3 images on the right show the use of linear vs. bicubic interpolation vs. nearest neighbor (no interpolation). The "see also" section gives some more algorithms like this. Some are better at combining, some are better at preserving sharp features, some take longer to execute etc. – Realz Slaw Nov 4 '13 at 13:56
• (continued) Er, I meant a "related problem". Also see dsp.SE, you can cross-post there as well (can you link to the cross posts please? I am curious about SO and dsp.SE answers). – Realz Slaw Nov 4 '13 at 14:13
• @RealzSlaw , Additional factors in this particular implementation is that it must be able to run on a comparably weak processor (handheld devices) so short execution time is preferred. It must also take into account that the processed dataset is just a subset of a much larget set. More concretely a view of a map with a set of samplepoints that is a part of a larger map with a superset of samplepoints. – Einar Sundgren Nov 4 '13 at 14:31
• You should put those additional factors into the question. Be aware that cs.SE is usually concerned mostly with theoretical efficiency, not actual efficiency. Also, if you are doing different scales, you should look up "mipmaps" (where you preprocess the interpolated images at different scales) and "trilinear interpolation" (where you use two scales and interpolate between them; this is very effective for video-games and multi-resolution textures). Also, you should know that these algorithms tend to be able to efficiently run on a GPU, so your device might be able to take advantage of that. – Realz Slaw Nov 4 '13 at 15:27
• Please don't cross-post simultaneously on multiple Stack Exchange sites -- that is frowned upon. Instead, pick one site to post on. If you're not sure where is best to ask, you can check first on meta. Now that you've cross-posted, you can choose one site where you want your question to appear, then click on the "flag" button underneath the question on the 2 other sites to flag it for moderator attention and ask them to close the other clones or merge them with the copy on the 1 site where you want to have it. – D.W. Nov 4 '13 at 18:49