Skip to content

Commit 7680809

Browse files
committed
test, doc a perspective projection
1 parent cc6ec0a commit 7680809

2 files changed

Lines changed: 18 additions & 5 deletions

File tree

lib/PDL/Transform.pd

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3888,9 +3888,17 @@ can continuously warp an image plane so that C<ncoords + 2> arbitrarily chosen
38883888
points exactly map to the same number of other arbitrarily chosen points. They
38893889
have the property that straight lines remain straight after transformation.
38903890

3891+
=for example
3892+
3893+
# perspective projection 3D -> 2D
3894+
$t_proj = t_projective(
3895+
src => pdl('1 1 1; -1 1 1; -1 -1 1; 1 -1 1; 2 2 2; -2 -2 2'),
3896+
dst => pdl('0 1000; 1000 1000; 1000 0; 0 0; 0 1000; 1000 0'),
3897+
);
3898+
38913899
You can specify your projective transformation directly in homogeneous
38923900
coordinates, or (as of 2.104, not just in 2 dimensions) as a set
3893-
of C<ncoords + 2> unique points that
3901+
of unique points that
38943902
are mapped one to the other by the transformation.
38953903

38963904
Projective transforms are quasi-linear because they are most easily
@@ -3936,8 +3944,7 @@ For example, specifying
39363944
maps the origin and the point (0,1) to themselves, the point (5,9)
39373945
to (5,8), and the point (9,4) to (9,3).
39383946

3939-
Added in 2.104. Works on any number of dimensions, the same for
3940-
C<src> and C<dst> (a homography).
3947+
Added in 2.104. Works on any number of dimensions.
39413948

39423949
=item p, point, points, Points
39433950

t/transform.t

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,15 @@ use Test::Exception;
5858
0 0 0 1 1 1 -1.463864 -1.463864 -1.463864
5959
'), 'right design matrix';
6060
$t_proj = t_projective(
61-
m => pdl('-500 0 500 0; 0 500 500 0; 0 0 1 0'),
61+
m => my $perspective_matrix = pdl('-500 0 500 0; 0 500 500 0; 0 0 1 0'),
6262
);
63-
is_pdl $t_proj->apply(my $in32 = pdl('0 -1 -1; 4 2 -10')), my $out32 = pdl('500 1000; 700 400'), 'project 3->2 with matrix';
63+
is_pdl $t_proj->apply(my $in32 = pdl('0 -1 -1; 4 2 -10')), my $out32 = pdl('500 1000; 700 400'), 'project perspective 3->2 with matrix';
64+
$t_proj = t_projective(
65+
src => my $src32perspective = pdl('1 1 1; -1 1 1; -1 -1 1; 1 -1 1; 2 2 2; -2 -2 2'),
66+
dst => my $dst32perspective = pdl('0 1000; 1000 1000; 1000 0; 0 0; 0 1000; 1000 0'),
67+
);
68+
is_pdl $t_proj->{params}{matrix}, $perspective_matrix, {test_name=>'perspective matrix from src/dst', atol=>1e-2};
69+
is_pdl $t_proj->apply($in32), $out32, 'project perspective 3->2 with src/dst';
6470
$t_proj = t_projective(
6571
src => my $src3 = pdl('0 0 0; 1 0 0; 0 1 0; 1 1 0; 0 0 1'),
6672
dst => my $dst3 = pdl('1 0 0; 2 1 0; -1 3 0; 0 4 0; 1 0 1'),

0 commit comments

Comments
 (0)