Imager::Filters - Entire Image Filtering Operations
use Imager;
$img = ...;
$img->filter(type=>'autolevels'); $img->filter(type=>'autolevels', lsat=>0.2); $img->filter(type=>'turbnoise')
# and lots others
load_plugin("dynfilt/dyntest.so") or die "unable to load plugin\n";
$img->filter(type=>'lin_stretch', a=>35, b=>200);
unload_plugin("dynfilt/dyntest.so") or die "unable to load plugin\n";
$out = $img->difference(other=>$other_img);
Filters are operations that have similar calling interface.
Here is a list of the filters that are always avaliable in Imager.
This list can be obtained by running the filterlist.perl
script
that comes with the module source.
Filter Arguments Default value autolevels lsat 0.1 usat 0.1 skew 0
bumpmap bump lightx lighty elevation 0 st 2
bumpmap_complex bump channel 0 tx 0 ty 0 Lx 0.2 Ly 0.4 Lz -1 cd 1.0 cs 40.0 n 1.3 Ia (0 0 0) Il (255 255 255) Is (255 255 255)
contrast intensity
conv coef
fountain xa ya xb yb ftype linear repeat none combine none super_sample none ssample_param 4 segments(see below)
gaussian stddev
gradgen xo yo colors dist
hardinvert
mosaic size 20
noise amount 3 subtype 0
postlevels levels 10
radnoise xo 100 yo 100 ascale 17.0 rscale 0.02
turbnoise xo 0.0 yo 0.0 scale 10.0
unsharpmask stddev 2.0 scale 1.0
watermark wmark pixdiff 10 tx 0 ty 0
All parameters must have some value but if a parameter has a default value it may be omitted when calling the filter function.
A reference of the filters follows:
renders a fountain fill, similar to the gradient tool in most paint software. The default fill is a linear fill from opaque black to opaque white. The points A(xa, ya) and B(xb, yb) control the way the fill is performed, depending on the ftype parameter:
The repeat option controls how the fill is repeated for some ftypes after it leaves the AB range:
By default the fill simply overwrites the whole image (unless you have parts of the range 0 through 1 that aren't covered by a segment), if any segments of your fill have any transparency, you can set the combine option to 'normal' to have the fill combined with the existing pixels. See the description of combine in Imager/Fill.
If your fill has sharp edges, for example between steps if you use repeat set to 'triangle', you may see some aliased or ragged edges. You can enable super-sampling which will take extra samples within the pixel in an attempt anti-alias the fill.
The possible values for the super_sample option are:
You can control the level of sampling by setting the ssample_param option. This is roughly the number of points sampled, but depends on the type of sampling.
The segments option is an arrayref of segments. You really should use the Imager::Fountain class to build your fountain fill. Each segment is an array ref containing:
Don't forget to use Imager::Fountain instead of building your own. Really. It even loads GIMP gradient files.
performs a gaussian blur of the image, using stddev as the standard deviation of the curve used to combine pixels, larger values give bigger blurs. For a definition of Gaussian Blur, see:
http://www.maths.abdn.ac.uk/~igc/tch/mx4002/notes/node99.html
A demonstration of most of the filters can be found at:
http://www.develop-help.com/imager/filters.html
(This is a slow link.)
It is possible to add filters to the module without recompiling the module itself. This is done by using DSOs (Dynamic shared object) avaliable on most systems. This way you can maintain our own filters and not have to get me to add it, or worse patch every new version of the Module. Modules can be loaded AND UNLOADED at runtime. This means that you can have a server/daemon thingy that can do something like:
load_plugin("dynfilt/dyntest.so") or die "unable to load plugin\n";
$img->filter(type=>'lin_stretch', a=>35, b=>200);
unload_plugin("dynfilt/dyntest.so") or die "unable to load plugin\n";
Someone decides that the filter is not working as it should - dyntest.c modified and recompiled.
load_plugin("dynfilt/dyntest.so") or die "unable to load plugin\n";
$img->filter(%hsh);
An example plugin comes with the module - Please send feedback to addi@umich.edu if you test this.
Note: This seems to test ok on the following systems: Linux, Solaris, HPUX, OpenBSD, FreeBSD, TRU64/OSF1, AIX. If you test this on other systems please let me know.
You can create a new image that is the difference between 2 other images.
my $diff = $img->difference(other=>$other_img);
For each pixel in $img that is different to the pixel in $other_img, the pixel from $other_img is given, otherwise the pixel is transparent black.
This can be used for debugging image differences ("Where are they different?"), and for optimizing animated GIFs.
Note that $img and $other_img must have the same number of channels. The width and heigh of $diff will be the minimum of each of the width and height of $img and $other_img.