(none) imager-devel
/ help / lists / applications / search /

Interpolated pixel sampling with transform2

From: Bruno Postle (
Date: Sat 19 Apr 2003 - 13:29:38 GMT

  • Next message: Bruno Postle: "Re: Interpolated pixel sampling with transform2"

    Hi, I have a question about the Imager::transform2 function.

    My problem is that the getp1() operator returns a sampled pixel
    rather than an interpolated pixel.

    This is strange since the rotate() function (for example) does seem
    to be using some form of interpolation - I guess I'm missing a way
    of "turning-on" interpolated sampling?

    Here is what I'm trying to do; this example is for correction of
    optical barrel distortion in photographs.

    My original photo:


    Photo distorted using Imager::Transform2():


    What the distortion would look like with 'spline16' interpolation:


    Script used:

        use strict;
        use warnings;
        use Imager;
        my $in = shift;
        my $out = shift;
        my $img = new Imager;
           $img->open (file => $in) or die $img->errstr;
        # ridiculous barrel distortion
        my ($a, $b, $c) = (0, 1.2, 0);
        # barrel correction parameters for an Olympus C860L
        # my ($a, $b, $c) = (0.0096, -0.0238, -0.0103);
        my $opts = { expr => "w2=w/2;h2=h/2;
                              return getp1((x-w2)*foo+w2,(y-h2)*foo+h2)" };
        my $output = Imager::transform2 ($opts, $img) or die $Imager::ERRSTR;
           $output->write (file => $out) or die $output->errstr;