As part of working on a PDL version of
Animated Heatmap, it was necessary to make PDL able to turn a field of floating-point numbers into a heatmap, like
Imager::Heatmap's
draw method does. Cue
PDL::Graphics::ColorSpace!
use PDL;
use PDL::Graphics::Simple;
use PDL::Graphics::ColorSpace;
sub as_heatmap {
my ($d) = @_;
my $max = $d->max;
die "as_heatmap: can't work if max == 0" if $max == 0;
$d /= $max; # negative OK
my $hue = (1 - $d)*240;
$d = cat($hue, pdl(1), pdl(1));
(hsv_to_rgb($d->mv(-1,0)) * 255)->byte->mv(0,-1);
}
imag as_heatmap(rvals 300,300);