HASM has asked for the wisdom of the Perl Monks concerning the following question:
At a given point of some processing I have a list of polygons (an array of arrays of x y coordinates).
I want to generate a .png image of the filled polygons. There are a few modules I can use, GD, Imager, ImageMagick, PDL, maybe more.
I've tried GD vs Imager as in:
use GD; my $img = new GD::Image ($width, $height); my $black = $img->colorAllocate (0,0,0); my $white = $img->colorAllocate (255,255,255); map { my $polygon = GD::Polygon->new; map { $polygon->addPt (round ($_->[0] * $scale - $minx), round ($maxy - $_->[1] * $scale)); } @{$_}; $img->filledPolygon ($polygon,$white); } @polygons; print $img->png ();
use Imager; my $img = Imager->new (xsize=>$width, ysize=>$height, channels=>1, bits=>8); map { my @polygon = (); map { push (@polygon, [round ($_->[0] * $scale - $minx), round ($maxy - $_->[1] * $scale)]) } @{$_}; $img->polygon (points=>\@polygon, color=>'white'); } @polygons; $img->write (fd => fileno(STDOUT), type=>'png');
For a sample set size of 12690 polygons, generating a 7917x38558 image, the GD approach runs in about 7 seconds, the Imager approach runs in about 209 seconds, a very large difference.
Cursory inspection with top reveals very similar memory and CPU requirements
What am I overlooking, or is this the way it is?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Filling polygons: Imager vs GD
by BrowserUk (Patriarch) on Sep 26, 2013 at 05:05 UTC | |
|
Re: Filling polygons: Imager vs GD
by stonecolddevin (Parson) on Sep 26, 2013 at 21:01 UTC | |
|
Re: Filling polygons: Imager vs GD
by tonyc (Hermit) on Oct 01, 2013 at 23:04 UTC |