Filters

A brief demonstration of Imager's filters.

The program given below uses Imager 0.39pre.

Rather than calling the filter() function inline for each image, which gets very boring, I built the %actions hash to hold every filter that needs to be called. This made it simpler to provide a command-line interface which could select which filters to use.

Each filter was used on a picture of the Vehicle Assembly Building at Kennedy Space Centre. I took this while in the USA, a few years ago.

#!/usr/bin/perl -w
use strict;
use Imager qw(:handy);

my $base = Imager->new;
$base->read(file=>'vab_base.png')
  or print "Could not read image: ",$base->errstr,"\n";
my $extra = Imager->new;
$extra->read(file=>'extra.jpg')
  or print "Could not read extra: ",$extra->errstr,"\n";

my %actions =
  (
   autolev=>{ type=>'autolevels' },
   autolev2=>{ type=>'autolevels', lsat=>0.2, usat=>0.2 },
   bumpmap=>{ type=>'bumpmap', bump=>$extra, lightx=>35, lighty=>30, 
	       st=>6},
   contrastlow=> { type=>'contrast', intensity=>0.8 },
   contrasthigh=> { type=>'contrast', intensity=>1.2 },
   conv111=>{type=>'conv', coef=>[1,1,1] },
   conv11211=>{type=>'conv', coef=>[1,1,2,1,1] },
   convsharp=>{type=>'conv', coef=>[-0.2, 1, -0.2] },
   gaussianlow=>{type=>'gaussian', stddev=>0.6 },
   gaussianmed=>{type=>'gaussian', stddev=>1 },
   gaussianhigh=>{type=>'gaussian', stddev=>4 },
   gradgen0=>{type=>'gradgen', 
              xo=>[ 100, 500, 250 ],
              yo=>[ 100, 100, 300 ],
              colors=>[NC("#FF8080"), NC("#00FF00"), NC("#000080")],
              dist=>0},
   gradgen1=>{type=>'gradgen', 
              xo=>[ 100, 500, 250 ],
              yo=>[ 100, 100, 300 ],
              colors=>[NC("#FF8080"), NC("#00FF00"), NC("#000080")],
              dist=>1},
   gradgen2=>{type=>'gradgen', 
              xo=>[ 100, 500, 250 ],
              yo=>[ 100, 100, 300 ],
              colors=>[NC("#FF8080"), NC("#00FF00"), NC("#000080")],
              dist=>2},
   hardinvert=>{type=>'hardinvert'},
   noise1=>{type=>'noise'},
   mosaic=>{type=>'mosaic', size=>10},
   noise2=>{type=>'noise', amount=>20},
   noise3=>{type=>'noise', amount=>20, subtype=>1},
   postlevels=>{type=>'postlevels', levels=>5},
   radnoise0=>{type=>'radnoise', xo=>300, yo=>200},
   radnoise1=>{type=>'radnoise', xo=>300, yo=>200, rscale=>0.02, ascale=>4},
   radnoise2=>{type=>'radnoise', xo=>300, yo=>200, rscale=>0.1, ascale=>8},
   turbnoise0=>{type=>'turbnoise'},
   turbnoise1=>{type=>'turbnoise', scale=>1},
   unsharpmask=>{type=>'unsharpmask'},
  );
my @want = sort keys %actions;
if (@ARGV) {
  @want = grep exists $actions{$_}, @ARGV;
  @want or print "None of @ARGV matched\n";
}

for my $which (@want) {
  print $which,"\n";
  my $filtered = $base->copy;
  $filtered->filter(%{$actions{$which}})
    or die "Filtering $which:",$filtered->errstr;
  $filtered->write(file=>"filters/vab_$which.jpg") or die "$which!";
}

Send errors/fixes/suggestions to: addi_at_umich.edu