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

Re: Interpolated pixel sampling with transform2

From: Bruno Postle (
08235@xyz.molar.is)
Date: Sat 19 Apr 2003 - 16:10:50 GMT

  • Next message: 08271@xyz.molar.is: "translucent fonts (fwd)"

    On Sat 19-Apr-2003 at 02:29:37 +0100, Bruno Postle wrote:
    >
    > 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?

    Ok, I've managed to build a linear interpolator within the 'expr'
    bit (see below). This is good enough for what I want to do now;
    though I'm still interested to find out what the right way of doing
    this might be?

    > 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;
    > rd=distance(w2,h2,x,y)/if(w<h,w2,h2);
    > foo=$a*rd*rd*rd+$b*rd*rd+$c*rd+1-$a-$b-$c;
                                m=(x-w2)*foo+w2;
                                n=(y-h2)*foo+h2;
                                                                                                                  
                                a=getp1(m,n)*(1-m+int(m))*(1-n+int(n));
                                b=getp1(m+1,n)*(m-int(m))*(1-n+int(n));
                                c=getp1(m,n+1)*(1-m+int(m))*(n-int(n));
                                d=getp1(m+1,n+1)*(m-int(m))*(n-int(n));
                                return (a+b+c+d)" };

    > my $output = Imager::transform2 ($opts, $img) or die $Imager::ERRSTR;
    >
    > $output->write (file => $out) or die $output->errstr;
    >
    > 1;



  •