I recommend trying things out in the pdl2 or perldl
interactive shell to get a feel for how these routines
work. The shells also have builtin help and apropos
commands for on-line PDL documentation.
In your code below, you have 1-D data that you
wish to transform---dimension 0 is size 1. Since
by default the transform assumes 2-D, you'll get
an error message.
pdl> p $f = t_linear(s=>3);
Linear (linear): fwd ok; inv ok.
Pre-add: 0
Post-add: 0
Forward matrix:
[
[3 0]
[0 3]
]
Inverse matrix:
[
[0.33333333 0]
[ 0 0.33333333]
]
pdl> p $a->info
PDL: Double D [1,2,10]
pdl> help PDL::Transform
NAME
PDL::Transform - Coordinate transforms, image warping, and N-D functions
SYNOPSIS
use PDL::Transform;
my $t = new PDL::Transform::<type>(<opt>)
$out = $t->apply($in) # Apply transform to some N-vectors
(Transform method)
$out = $in->apply($t) # Apply transform to some N-vectors (PDL method)
$im1 = $t->map($im); # Transform image coordinates (Transform method)
$im1 = $im->map($t); # Transform image coordinates (PDL method)
$t2 = $t->compose($t1); # compose two transforms
$t2 = $t x $t1; # compose two transforms (by analogy to
matrix mult.)
$t3 = $t2->inverse(); # invert a transform
$t3 = !$t2; # invert a transform (by analogy to logical "not")
DESCRIPTION
PDL::Transform is a convenient way to represent coordinate
transformations and resample images. It embodies functions mapping R^N
-> R^M, both with and without inverses. Provision exists for
parametrizing functions, and for composing them. You can use this part
of the Transform object to keep track of arbitrary functions mapping R^N
-> R^M with or without inverses.
The simplest way to use a Transform object is to transform vector data
between coordinate systems. The apply method accepts a PDL whose 0th
dimension is coordinate index (all other dimensions are threaded over)
and transforms the vectors into the new coordinate system.
....
Note the last paragraph above, the 0th dimension (left-most index)
is coordinate index (size is dimensionality of your points). I suspect
you actually have a set of (x,y) values. In that case, you would use
pdl> p $a = yvals(2,10)
[
[0 0]
[1 1]
[2 2]
[3 3]
[4 4]
[5 5]
[6 6]
[7 7]
[8 8]
[9 9]
]
pdl> p $a->apply($f)
[
[ 0 0]
[ 3 3]
[ 6 6]
[ 9 9]
[12 12]
[15 15]
[18 18]
[21 21]
[24 24]
[27 27]
]
In the above I used the yvals() routine to generate the coordinates
in $a (set is *very* slow) and I did not make a size-1 1st dimesion
since it did not look that you were actually using one.
Cheers,
Chris
On Mon, Aug 15, 2011 at 4:13 PM, Ben <[email protected]> wrote:
> Hi Chris,
>
> I just tried what you suggested, but now I seem to get a different kind of
> error:
>
> "Slice cannot start or end above limit at
> /usr/lib64/perl5/vendor_perl/PDL/Core.pm line 799."
>
> Code below. Ideas?
>
> #!/usr/bin/perl
>
> use PDL;
> use PDL::Matrix;
> use PDL::Transform;
>
> $a = zeroes(1,2, 10);
> for ($i = 0; $i < 10; $i++) {
> $a->set(0,0,$i,$i);
> $a->set(0,1,$i,$i);
> }
> print $a;
>
> $f = t_linear(s=>3);
> $d= $a->apply($f);
>
> print $d;
>
>
>
> _______________________________________________
> Perldl mailing list
> [email protected]
> http://mailman.jach.hawaii.edu/mailman/listinfo/perldl
>
_______________________________________________
Perldl mailing list
[email protected]
http://mailman.jach.hawaii.edu/mailman/listinfo/perldl