Page 2 of 5

Re: Heat map with lots of events

Posted: 2014-01-11T12:30:27-07:00
by fmw42
snibgo wrote:

Code: Select all

convert ^
  heatmap.png ^
  -auto-level ^
  ( -size 1x250 ^
    gradient:#004-#804 ^
    gradient:#804-#f00 ^
    gradient:#f00-#f80 ^
    gradient:#f80-#ff0 ^
    gradient:#ff0-#ffa ^
    +append ^
  ) ^
  -clut ^
  heatmap_coloured.png

Just curious, but do not each gradient need to be placed at different locations via -geometry or -page and composited?

Re: Heat map with lots of events

Posted: 2014-01-11T13:48:40-07:00
by snibgo
Oops, that should be "-append", not "+". Thanks.

It gives quite a nice clut from dark blue to light yellow. It isn't quite perfect in the sense that #804 and the other transitions are repeated. If each segment was 51 pixels wide the clut image would look like this:
Image
We can see the small kinks. When each segment is 250 pixels wide, I don't think the kinks matter.

Re: Heat map with lots of events

Posted: 2014-01-11T15:38:03-07:00
by DrEvil
Again thanks a lot. Is there a way to specify the geometry of the images based on their center or is it always upper left?

Re: Heat map with lots of events

Posted: 2014-01-11T15:41:07-07:00
by fmw42
DrEvil wrote:Again thanks a lot. Is there a way to specify the geometry of the images based on their center or is it always upper left?
If you use -gravity center -geometry ..., then if you are placing different gradients at different locations, it will position the centers of the gradients relative to the center of the background image.

Otherwise, the default is top left corner of the gradient relative to the top left corner of the background.

Re: Heat map with lots of events

Posted: 2014-01-11T16:40:16-07:00
by DrEvil
Is there a way to create gradients off of line strips in a way that doesn't over saturate the overlapping pixels of neighboring lines(such as if you did each line segments separately)?

Re: Heat map with lots of events

Posted: 2014-01-11T17:20:06-07:00
by snibgo
I don't understand the question. Do you mean the colours in the clut? My chart above shows the actual colours in the bottom strip. They can be any colours you want. My script has 5 gradients, but you can have any number you like, from one upwards. Each transition can be any colour you want.

Re: Heat map with lots of events

Posted: 2014-01-11T19:03:54-07:00
by DrEvil
Suppose you have a series of line segments that make up a line strip of arbitrary length. The desire is to draw this line strip from point to point representing heat map events such as a persons locational history(where they moved around the environment, etc). Like the radial gradients, I would ideally be able to render these paths with a width and radial gradient falloff.

I would think that the way to accomplish this is to render the line sequence itself into an image with a gradient falloff 'away' from the line, as if rendering the line with a width but the width having a gradient falloff perpendicular to the line. It's that line gradient in particular that I'm asking about. Perhaps that would just be a polygon of the width of the event with a gradient along the polygon direction so that it falls off to the sides?

Drawing the lines appears pretty easy, the part I'm not sure of is the gradient falloff away from the lines based on a configurable width

Re: Heat map with lots of events

Posted: 2014-01-11T21:13:09-07:00
by fmw42
How wide are the lines. If only one pixel, then the best you can do is just anti-alias or linear blur the line, but the blurring would thicken the line. There is no way to make a one-pixel thick line have a gradient in the direction perpendicular to the line direction and keep it one pixel wide.

For blurring perpendicular to the line direction, see -morphology convolve blur:...

http://www.imagemagick.org/Usage/convolve/#blur

But that only works if your lines are horizontal or vertical. You have to choose the angle for -blur as 0 or 90 as appropriate to the direction of your line.

You can convert the gaussian shape to linear by replacing 0xsigma with radiusx65535

Re: Heat map with lots of events

Posted: 2014-01-11T21:39:01-07:00
by DrEvil
It seems that I'll need to generate a batch file and such with individual commands for each event to be accumulated into the heatmap prior to colorization? That's fine, but if they are individual commands, does that mean convert.exe has to open, parse, draw, save and close the file for each event? I'm concerned with the performance of that for event counts up in the tens of thousands. Is there a way to feed those commands into an instance of convert.exe that can avoid tends of thousands of basic I/O operations and batch all the event drawing into 1 opening of the file ? I may ultimately be processing large files with which the file IO of opening and closing it tens of thousands of times could become a significant performance bottleneck.

Re: Heat map with lots of events

Posted: 2014-01-12T04:01:12-07:00
by snibgo
You can create a gradient from a line by blurring it. For example, draw a white line on a black background and "-blur 0x15", perhaps followed by "-auto-level". This will blur in all directions, creating rounded ends. To blur just in the direction perpendicular to the line, you can rotate the line so it is horizontal, blur vertically, and rotate back.

What is your platform? Unix, Windows or what? As I said upthread, you can have one long command that processes all the events, or perhaps a hundred at a time. Unix (or possibly Cygwin on Windows) might give you other piping options.

Re: Heat map with lots of events

Posted: 2014-01-12T11:08:54-07:00
by DrEvil
windows at the moment, but this may end up running on a web backend at some point

Re: Heat map with lots of events

Posted: 2014-01-12T11:55:41-07:00
by snibgo
On Windows, Powershell or Cygwin might be the geekiest options. I would just take the easy way: put the IM options for the thousands of events in an "at-file". This method is portable (as far as I know) across all environments.

For this method, create a file I will call heatmap.inc containing:

Code: Select all

  ( -size 100x100
    radial-gradient:
    -evaluate Multiply 0.25
  )
  -geometry +180+80
  -compose Plus -composite
  ( -size 100x100
    radial-gradient:
    -evaluate Multiply 0.50
  )
  -geometry +380+80
  -compose Plus -composite
I show just two events. Note there are no line continuation characters. Any percentage signs should not be doubled.

Then create heatmap.bat:

Code: Select all

convert ^
  -size 600x400 ^
  xc:black ^
  @heatmap.inc ^
  heatmap.png

Re: Heat map with lots of events

Posted: 2014-01-12T12:02:13-07:00
by DrEvil
perfect. thanks

Re: Heat map with lots of events

Posted: 2014-01-12T12:42:07-07:00
by DrEvil
Ok I'm trying to get the floating point part to work properly and I'm not sure what I'm doing wrong. Specifically, the accumulation isn't working how I expect it to. In the inc file, the 2nd event is double in order to test the accumulation and normalization. The expectation is that overlapping events will accumulate their values and then the auto level will then level based on the new min/max values. The documentation for auto_level sounds correct. Perhaps I am not accumulating the values correctly? I'm trying to set it to use a 32 bit floating point format so that there really isn't a ceiling to the accumulation.

Here's my batch file

Code: Select all

@echo off

echo Blending Events into Accumulation Image
convert -depth 32 -define quantum:format=floating-point -size 1000x1000 xc:black @heatmap.inc heatmap.tif

echo Applying Colorization
convert heatmap.tif -auto-level ( ^
	-size 1x250 ^
	gradient:#004-#804 ^
	gradient:#804-#f00 ^
	gradient:#f00-#f80 ^
	gradient:#f80-#ff0 ^
	gradient:#ff0-#ffa ^
	-append ) -clut heatmap_coloured.png

pause
And here's my inc file

Code: Select all

( -size 100x100 radial-gradient:  ) -gravity center -geometry +300+300 -compose Plus -composite

( -size 100x100 radial-gradient:  ) -gravity center -geometry +180+80 -compose Plus -composite
( -size 100x100 radial-gradient:  ) -gravity center -geometry +180+80 -compose Plus -composite
The 2nd event is doubled to test the accumulation and leveling. The end result should be that the more you stack an event, you should see the intensity of other events diminish.

Re: Heat map with lots of events

Posted: 2014-01-12T13:22:03-07:00
by snibgo
Please put up the resulting image (eg put it on dropbox.com and paste the URL here) and say what it is wrong with it.

Incidentally, if you want "-gravity center" you can put that just once rather than repeating it for every event.