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

Interpolated pixel sampling with transform2

From: Bruno Postle (
08199@xyz.molar.is)
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:

        http://bugbear.blackfish.org.uk/~bruno/imager-test/original.jpg

    Photo distorted using Imager::Transform2():

        http://bugbear.blackfish.org.uk/~bruno/imager-test/sampled.jpg

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

        http://bugbear.blackfish.org.uk/~bruno/imager-test/interpolated.jpg

    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;
                              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;
                              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;
        
        1;

    -- 
    Bruno
    



  •