I'm looking for some document开发者_如何学JAVAation on a heat map algorithm. I've found some implementations but they don't calculate the gradient the way I'm looking. Instead of calculating by "hits" I want to associate the data points with a value.
The only reasource I've found is the source-code from openheatmap.com. This is some great stuff but I'm looking to create the gradients on the fly rather than from a historical data set .
I'm looking to create a real-time heatmap similar to a world of tweets.
From the answers I've received I've gathered my own conclusion, please comment on its accuracy.
So for a heat map based on "hits" you have a matrix of pixels with value of 0:
[ 0 0 0 ]
[ 0 0 0 ]
[ 0 0 0 ]
When you have a hit you increment the corresponding element.
[ 1 3 2 ]
[ 4 1 2 ]
[ 0 3 5 ]
If you have values though instead of hits you add the value to the matrix. For example lets use dollar amounts which give this example matrix:
[ $20.34 $42.42 $55.23 ]
[ $45.87 $00.87 $03.75 ]
[ $08.99 $32.05 $88.65 ]
We then normalize the data. This yields:
[ .897 .973 .984 ]
[ .977 .087 .351 ]
[ .669 .959 .994 ]
Now you can spread or blur this using your algorithm of choice. Like the Gaussian Blur.
You can then apply what ever gradient you want to these values.
Hmm, if you want to extrapolate a "heat map" (regular grid of pixel values) from a scatter of "hits" (like in World of Tweets), an obvious way to do this is to first just count for every pixel the number of hits at that exact pixel (i.e. quantize the hit locations to the grid), and the apply a convolution filter, e.g. a gaussian filter, on the data to "blend" it. See http://en.wikipedia.org/wiki/Gaussian_blur.
If you can read/convert OpenGL fragment shader - here it is. Real-time just means that you must re-calculate heatmap values on the fly.
hth!
I just glanced at the World of Tweets. It looks like each tweet adds some value to the location, and all locations decay - probably exponentially over time. This will allow data to be added at irregular times while displaying what looks like an average of sorts. So for each pixel in the map do:
At fixed time interval: output = output * 0.99
When a burp happens: output += value_of_burp
These are to be applied separately for each pixel in your map. You can spread the value out over pixels using whatever smearing you want - even apply the same value over a circle. Of course the 0.99 should be manually adjusted until you get something you like.
The exponential decay means that even very active pixels will be have a finite output - in other words it's stable.
精彩评论