Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Creating Heat Map in perl

by nevdka (Monk)
on Sep 04, 2013 at 05:25 UTC ( #1052215=note: print w/ replies, xml ) Need Help??


in reply to Creating Heat Map in perl

I haven't used that module, but you will likely get better responses if you show the code you have tried, and tell us where it's not doing what you want it to do.

Oh, and put the code inside <code></code> tags, or some of the monks will get grumpy.


Comment on Re: Creating Heat Map in perl
Download Code
Re^2: Creating Heat Map in perl
by huzefa52 (Novice) on Sep 04, 2013 at 07:07 UTC
    Hi, Thanks for the reply, I am using below code, it is giving me following error. Can't locate object method "Imager=HASH(0xfeeb4d0)" via package "Imager::Heatmap" at heatmap.pl line 28.
    #!/usr/bin/perl -w use strict; #use warnings; use utf8; use XSLoader; use Carp; use Imager; use List::Util qw/ max /; use Imager; use Imager::Heatmap; my $hmap = Imager::Heatmap->new( xsize => 640, # Image width ysize => 480, # Image height xsigma => 10, # Sigma value of X-direction ysigma => 10, # Sigma value of Y-direction ); my @piont_datas = ( [ 10, 20, 50 ], [ 20, 40, 70 ] ); # Add point datas to construct density matrix $hmap->insert_datas(@piont_datas); # @point_datas should be: ( [ x1, y +1, weight1 ], [ x2, y2, weight2 ] ... ) #$hmap->insert_datas(...); # You can call multiple times to add large +data that cannot process at a time. # After adding datas, you could get heatmap as Imager instance. my $img = $hmap->draw; # Returned image is 4-channels image. So you can overlay it on other i +mages. my $base_img->rubthrough( src => $hmap->$img ); # Overlay on other im +ages(see Imager::Transformations) $img = Imager->new( xsize => $hmap->xsize, ysize => $hmap->ysize, channels => 4, ); # And you can access probability density matrix using matrix method if + you like. # In case, maybe you would like to create some graduations which be as +signed to color of heatmap and its value. $hmap->matrix;

      So, what is in line 28? Have you looked at it and checked it that it means what you intend?

      my $base_img->rubthrough( src => $hmap->$img ); # Overlay on other im +ages(see Imager::Transformations)

      Please explain for every item in English what it is supposed to mean. Especially, explain the construct $hmap->$img.

      Very minor thing s/piont_datas/point_datas/g;. The only reason the code doesn't generate an error is because you made this spelling mistake consistently.
      What is the last line doing? $hmap->matrix simply returns a reference to the density matrix - on its own it does nothing.
      If you spot any bugs in my solutions, it's because I've deliberately left them in as an exercise for the reader! :-)
        Thanks for finding my mistake. Now, I am getting the heatmap image in my $img variable i.e $img = $hmap->draw; But how to use this $img value to get image in gif/png format. Because there is no plot option defined in Imager::Heatmap module.

      The synopsis for Imager::Heatmap can not be run as is. It doesn't create $base_img, it doesn't show how to properly use matrix, etc. So it is no surprise that what you ended up with didn't work.

      Try this as a starting point. It uses your data and creates a png file in the current directory.

      #!/bin/env perl use strict; use warnings; use Imager::Heatmap; my $hmap = Imager::Heatmap->new( xsize => 640, # Image width ysize => 480, # Image height xsigma => 10, # Sigma value of X-direction ysigma => 10, # Sigma value of Y-direction ); # @point_datas should be: ( [ x1, y1, weight1 ], [ x2, y2, weight2 ] . +.. ) my @point_datas = ( [ 10, 20, 50 ], [ 20, 40, 70 ] ); # Add point datas to construct density matrix $hmap->insert_datas(@point_datas); # After adding datas, get heatmap as Imager instance. my $img = $hmap->draw; # create png file in current directory $img->write( file => './hm.png' );

      Here's the generated heatmap image.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1052215]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (11)
As of 2014-10-31 14:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (217 votes), past polls