"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "GENERATED/PDL/Image2D.pm" between
PDL-2.081.tar.gz and PDL-2.082.tar.gz

About: PDL (Perl Data Language) aims to turn perl into an efficient numerical language for scientific computing (similar to IDL and MatLab).

Image2D.pm  (PDL-2.081):Image2D.pm  (PDL-2.082)
# #
# GENERATED WITH PDL::PP! Don't modify! # GENERATED WITH PDL::PP! Don't modify!
# #
package PDL::Image2D; package PDL::Image2D;
our @EXPORT_OK = qw( conv2d med2d med2df box2d patch2d patchbad2d max2d_ind cent roid2d crop cc8compt cc4compt ccNcompt polyfill pnpoly polyfillv rotnewsz rot2d bilin2d rescale2d fitwarp2d applywarp2d warp2d warp2d_kernel warp2d_kernel ); our @EXPORT_OK = qw( conv2d med2d med2df box2d patch2d patchbad2d max2d_ind cent roid2d crop cc8compt cc4compt ccNcompt polyfill pnpoly polyfillv rotnewsz rot2d bilin2d rescale2d fitwarp2d applywarp2d warp2d warp2d_kernel );
our %EXPORT_TAGS = (Func=>\@EXPORT_OK); our %EXPORT_TAGS = (Func=>\@EXPORT_OK);
use PDL::Core; use PDL::Core;
use PDL::Exporter; use PDL::Exporter;
use DynaLoader; use DynaLoader;
our @ISA = ( 'PDL::Exporter','DynaLoader' ); our @ISA = ( 'PDL::Exporter','DynaLoader' );
push @PDL::Core::PP, __PACKAGE__; push @PDL::Core::PP, __PACKAGE__;
bootstrap PDL::Image2D ; bootstrap PDL::Image2D ;
skipping to change at line 40 skipping to change at line 40
=head1 SYNOPSIS =head1 SYNOPSIS
use PDL::Image2D; use PDL::Image2D;
=cut =cut
use PDL; # ensure qsort routine available use PDL; # ensure qsort routine available
use PDL::Math; use PDL::Math;
use Carp; use Carp;
#line 48 "Image2D.pm"
my %boundary2value = (Reflect=>1, Truncate=>2, Replicate=>3);
#line 50 "Image2D.pm"
=head1 FUNCTIONS =head1 FUNCTIONS
=cut =cut
#line 951 "/home/osboxes/pdl-code/blib/lib/PDL/PP.pm" #line 960 "/home/osboxes/pdl-code/blib/lib/PDL/PP.pm"
#line 63 "Image2D.pm" #line 65 "Image2D.pm"
#line 951 "/home/osboxes/pdl-code/blib/lib/PDL/PP.pm" #line 960 "/home/osboxes/pdl-code/blib/lib/PDL/PP.pm"
#line 68 "Image2D.pm" #line 70 "Image2D.pm"
#line 951 "/home/osboxes/pdl-code/blib/lib/PDL/PP.pm" #line 960 "/home/osboxes/pdl-code/blib/lib/PDL/PP.pm"
#line 73 "Image2D.pm" #line 75 "Image2D.pm"
#line 949 "/home/osboxes/pdl-code/blib/lib/PDL/PP.pm" #line 958 "/home/osboxes/pdl-code/blib/lib/PDL/PP.pm"
=head2 conv2d =head2 conv2d
=for sig =for sig
Signature: (a(m,n); kern(p,q); [o]b(m,n); int opt) Signature: (a(m,n); kern(p,q); [o]b(m,n); indx [t]mapi(isize); indx [t]mapj(js ize); int opt)
=for ref =for ref
2D convolution of an array with a kernel (smoothing) 2D convolution of an array with a kernel (smoothing)
For large kernels, using a FFT routine, For large kernels, using a FFT routine,
such as L<fftconvolve()|PDL::FFT/fftconvolve()> in C<PDL::FFT>, such as L<PDL::FFT/fftconvolve>,
will be quicker. will be quicker.
=for usage =for usage
$new = conv2d $old, $kernel, {OPTIONS} $new = conv2d $old, $kernel, {OPTIONS}
=for example =for example
$smoothed = conv2d $image, ones(3,3), {Boundary => Reflect} $smoothed = conv2d $image, ones(3,3), {Boundary => Reflect}
skipping to change at line 94 skipping to change at line 96
(i.e. wrap around axis) (i.e. wrap around axis)
=> Reflect - reflect at boundary => Reflect - reflect at boundary
=> Truncate - truncate at boundary => Truncate - truncate at boundary
=> Replicate - repeat boundary pixel values => Replicate - repeat boundary pixel values
=for bad =for bad
Unlike the FFT routines, conv2d is able to process bad values. Unlike the FFT routines, conv2d is able to process bad values.
=cut =cut
#line 120 "Image2D.pm" #line 122 "Image2D.pm"
#line 950 "/home/osboxes/pdl-code/blib/lib/PDL/PP.pm" #line 959 "/home/osboxes/pdl-code/blib/lib/PDL/PP.pm"
sub PDL::conv2d { sub PDL::conv2d {
my $opt; $opt = pop @_ if ref($_[$#_]) eq 'HASH'; my $opt; $opt = pop @_ if ref($_[$#_]) eq 'HASH';
die 'Usage: conv2d( a(m,n), kern(p,q), [o]b(m,n), {Options} )' die 'Usage: conv2d( a(m,n), kern(p,q), [o]b(m,n), {Options} )'
if $#_<1 || $#_>2; if $#_<1 || $#_>2;
my($x,$kern) = @_; my($x,$kern) = @_;
my $c = $#_ == 2 ? $_[2] : $x->nullcreate; my $c = $#_ == 2 ? $_[2] : $x->nullcreate;
PDL::_conv2d_int($x,$kern,$c, PDL::_conv2d_int($x,$kern,$c,
(!(defined $opt && exists $$opt{Boundary}))?0: (!($opt && exists $$opt{Boundary}))?0:$boundary2value{$$opt{Boundary}}
(($$opt{Boundary} eq "Reflect") + );
2*($$opt{Boundary} eq "Truncate") +
3*($$opt{Boundary} eq "Replicate")));
return $c; return $c;
} }
#line 140 "Image2D.pm" #line 140 "Image2D.pm"
#line 951 "/home/osboxes/pdl-code/blib/lib/PDL/PP.pm" #line 960 "/home/osboxes/pdl-code/blib/lib/PDL/PP.pm"
*conv2d = \&PDL::conv2d; *conv2d = \&PDL::conv2d;
#line 147 "Image2D.pm" #line 147 "Image2D.pm"
#line 949 "/home/osboxes/pdl-code/blib/lib/PDL/PP.pm" #line 958 "/home/osboxes/pdl-code/blib/lib/PDL/PP.pm"
=head2 med2d =head2 med2d
=for sig =for sig
Signature: (a(m,n); kern(p,q); [o]b(m,n); double+ [t]tmp(pq); int opt) Signature: (a(m,n); kern(p,q); [o]b(m,n); double+ [t]tmp(pq); indx [t]mapi(isi ze); indx [t]mapj(jsize); int opt)
=for ref =for ref
2D median-convolution of an array with a kernel (smoothing) 2D median-convolution of an array with a kernel (smoothing)
Note: only points in the kernel E<gt>0 are included in the median, other Note: only points in the kernel E<gt>0 are included in the median, other
points are weighted by the kernel value (medianing lots of zeroes points are weighted by the kernel value (medianing lots of zeroes
is rather pointless) is rather pointless)
=for usage =for usage
skipping to change at line 159 skipping to change at line 159
=> Replicate - repeat boundary pixel values => Replicate - repeat boundary pixel values
=for bad =for bad
Bad values are ignored in the calculation. If all elements within the Bad values are ignored in the calculation. If all elements within the
kernel are bad, the output is set bad. kernel are bad, the output is set bad.
=cut =cut
#line 194 "Image2D.pm" #line 194 "Image2D.pm"
#line 950 "/home/osboxes/pdl-code/blib/lib/PDL/PP.pm" #line 959 "/home/osboxes/pdl-code/blib/lib/PDL/PP.pm"
sub PDL::med2d { sub PDL::med2d {
my $opt; $opt = pop @_ if ref($_[$#_]) eq 'HASH'; my $opt; $opt = pop @_ if ref($_[$#_]) eq 'HASH';
die 'Usage: med2d( a(m,n), kern(p,q), [o]b(m,n), {Options} )' die 'Usage: med2d( a(m,n), kern(p,q), [o]b(m,n), {Options} )'
if $#_<1 || $#_>2; if $#_<1 || $#_>2;
my($x,$kern) = @_; my($x,$kern) = @_;
croak "med2d: kernel must contain some positive elements.\n" croak "med2d: kernel must contain some positive elements.\n"
if all( $kern <= 0 ); if all( $kern <= 0 );
my $c = $#_ == 2 ? $_[2] : $x->nullcreate; my $c = $#_ == 2 ? $_[2] : $x->nullcreate;
PDL::_med2d_int($x,$kern,$c, PDL::_med2d_int($x,$kern,$c,
(!(defined $opt && exists $$opt{Boundary}))?0: (!($opt && exists $$opt{Boundary}))?0:$boundary2value{$$opt{Boundary}}
(($$opt{Boundary} eq "Reflect") + );
2*($$opt{Boundary} eq "Truncate") +
3*($$opt{Boundary} eq "Replicate")));
return $c; return $c;
} }
#line 215 "Image2D.pm" #line 213 "Image2D.pm"
#line 951 "/home/osboxes/pdl-code/blib/lib/PDL/PP.pm" #line 960 "/home/osboxes/pdl-code/blib/lib/PDL/PP.pm"
*med2d = \&PDL::med2d; *med2d = \&PDL::med2d;
#line 222 "Image2D.pm" #line 220 "Image2D.pm"
#line 949 "/home/osboxes/pdl-code/blib/lib/PDL/PP.pm" #line 958 "/home/osboxes/pdl-code/blib/lib/PDL/PP.pm"
=head2 med2df =head2 med2df
=for sig =for sig
Signature: (a(m,n); [o]b(m,n); int __p_size; int __q_size; int opt) Signature: (a(m,n); [o]b(m,n); indx [t]mapi(isize); indx [t]mapj(jsize); int p _size=>p; int q_size=>q; int opt)
=for ref =for ref
2D median-convolution of an array in a pxq window (smoothing) 2D median-convolution of an array in a pxq window (smoothing)
Note: this routine does the median over all points in a rectangular Note: this routine does the median over all points in a rectangular
window and is not quite as flexible as C<med2d> in this regard window and is not quite as flexible as C<med2d> in this regard
but slightly faster instead but slightly faster instead
=for usage =for usage
skipping to change at line 222 skipping to change at line 220
=> Reflect - reflect at boundary => Reflect - reflect at boundary
=> Truncate - truncate at boundary => Truncate - truncate at boundary
=> Replicate - repeat boundary pixel values => Replicate - repeat boundary pixel values
=for bad =for bad
med2df does not process bad values. med2df does not process bad values.
It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
=cut =cut
#line 271 "Image2D.pm" #line 269 "Image2D.pm"
#line 950 "/home/osboxes/pdl-code/blib/lib/PDL/PP.pm" #line 959 "/home/osboxes/pdl-code/blib/lib/PDL/PP.pm"
sub PDL::med2df { sub PDL::med2df {
my $opt; $opt = pop @_ if ref($_[$#_]) eq 'HASH'; my $opt; $opt = pop @_ if ref($_[$#_]) eq 'HASH';
die 'Usage: med2df( a(m,n), [o]b(m,n), p, q, {Options} )' die 'Usage: med2df( a(m,n), [o]b(m,n), p, q, {Options} )'
if $#_<2 || $#_>3; if $#_<2 || $#_>3;
my($x,$p,$q) = @_; my($x,$p,$q) = @_;
croak "med2df: kernel must contain some positive elements.\n" croak "med2df: kernel must contain some positive elements.\n"
if $p == 0 && $q == 0; if $p == 0 && $q == 0;
my $c = $#_ == 3 ? $_[3] : $x->nullcreate; my $c = $#_ == 3 ? $_[3] : $x->nullcreate;
&PDL::_med2df_int($x,$c,$p,$q, &PDL::_med2df_int($x,$c,$p,$q,
(!(defined $opt && exists $$opt{Boundary}))?0: (!($opt && exists $$opt{Boundary}))?0:$boundary2value{$$opt{Boundary}}
(($$opt{Boundary} eq "Reflect") + );
2*($$opt{Boundary} eq "Truncate") +
3*($$opt{Boundary} eq "Replicate")));
return $c; return $c;
} }
#line 292 "Image2D.pm" #line 288 "Image2D.pm"
#line 951 "/home/osboxes/pdl-code/blib/lib/PDL/PP.pm" #line 960 "/home/osboxes/pdl-code/blib/lib/PDL/PP.pm"
*med2df = \&PDL::med2df; *med2df = \&PDL::med2df;
#line 299 "Image2D.pm" #line 295 "Image2D.pm"
#line 949 "/home/osboxes/pdl-code/blib/lib/PDL/PP.pm" #line 958 "/home/osboxes/pdl-code/blib/lib/PDL/PP.pm"
=head2 box2d =head2 box2d
=for sig =for sig
Signature: (a(n,m); [o] b(n,m); int wx; int wy; int edgezero) Signature: (a(n,m); [o] b(n,m); int wx; int wy; int edgezero)
=for ref =for ref
fast 2D boxcar average fast 2D boxcar average
skipping to change at line 281 skipping to change at line 277
better filters are around (e.g., use L</conv2d> with the appropriate better filters are around (e.g., use L</conv2d> with the appropriate
kernel). On the other hand it is fast and computational cost grows only kernel). On the other hand it is fast and computational cost grows only
approximately linearly with window size. approximately linearly with window size.
=for bad =for bad
box2d does not process bad values. box2d does not process bad values.
It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
=cut =cut
#line 342 "Image2D.pm" #line 338 "Image2D.pm"
#line 951 "/home/osboxes/pdl-code/blib/lib/PDL/PP.pm" #line 960 "/home/osboxes/pdl-code/blib/lib/PDL/PP.pm"
*box2d = \&PDL::box2d; *box2d = \&PDL::box2d;
#line 349 "Image2D.pm" #line 345 "Image2D.pm"
#line 949 "/home/osboxes/pdl-code/blib/lib/PDL/PP.pm" #line 958 "/home/osboxes/pdl-code/blib/lib/PDL/PP.pm"
=head2 patch2d =head2 patch2d
=for sig =for sig
Signature: (a(m,n); int bad(m,n); [o]b(m,n)) Signature: (a(m,n); int bad(m,n); [o]b(m,n))
=for ref =for ref
patch bad pixels out of 2D images using a mask patch bad pixels out of 2D images using a mask
skipping to change at line 314 skipping to change at line 310
C<$bad> is a 2D mask array where 1=bad pixel 0=good pixel. C<$bad> is a 2D mask array where 1=bad pixel 0=good pixel.
Pixels are replaced by the average of their non-bad neighbours; Pixels are replaced by the average of their non-bad neighbours;
if all neighbours are bad, the original data value is if all neighbours are bad, the original data value is
copied across. copied across.
=for bad =for bad
This routine does not handle bad values - use L</patchbad2d> instead This routine does not handle bad values - use L</patchbad2d> instead
=cut =cut
#line 384 "Image2D.pm" #line 380 "Image2D.pm"
#line 951 "/home/osboxes/pdl-code/blib/lib/PDL/PP.pm" #line 960 "/home/osboxes/pdl-code/blib/lib/PDL/PP.pm"
*patch2d = \&PDL::patch2d; *patch2d = \&PDL::patch2d;
#line 391 "Image2D.pm" #line 387 "Image2D.pm"
#line 949 "/home/osboxes/pdl-code/blib/lib/PDL/PP.pm" #line 958 "/home/osboxes/pdl-code/blib/lib/PDL/PP.pm"
=head2 patchbad2d =head2 patchbad2d
=for sig =for sig
Signature: (a(m,n); [o]b(m,n)) Signature: (a(m,n); [o]b(m,n))
=for ref =for ref
patch bad pixels out of 2D images containing bad values patch bad pixels out of 2D images containing bad values
skipping to change at line 348 skipping to change at line 344
if all neighbours are bad, the output is set bad. if all neighbours are bad, the output is set bad.
If the input ndarray contains I<no> bad values, then a straight copy If the input ndarray contains I<no> bad values, then a straight copy
is performed (see L</patch2d>). is performed (see L</patch2d>).
=for bad =for bad
patchbad2d handles bad values. The output ndarray I<may> contain patchbad2d handles bad values. The output ndarray I<may> contain
bad values, depending on the pattern of bad values in the input ndarray. bad values, depending on the pattern of bad values in the input ndarray.
=cut =cut
#line 425 "Image2D.pm" #line 421 "Image2D.pm"
#line 951 "/home/osboxes/pdl-code/blib/lib/PDL/PP.pm" #line 960 "/home/osboxes/pdl-code/blib/lib/PDL/PP.pm"
*patchbad2d = \&PDL::patchbad2d; *patchbad2d = \&PDL::patchbad2d;
#line 432 "Image2D.pm" #line 428 "Image2D.pm"
#line 949 "/home/osboxes/pdl-code/blib/lib/PDL/PP.pm" #line 958 "/home/osboxes/pdl-code/blib/lib/PDL/PP.pm"
=head2 max2d_ind =head2 max2d_ind
=for sig =for sig
Signature: (a(m,n); [o]val(); int [o]x(); int[o]y()) Signature: (a(m,n); [o]val(); int [o]x(); int[o]y())
=for ref =for ref
Return value/position of maximum value in 2D image Return value/position of maximum value in 2D image
Contributed by Tim Jeness Contributed by Tim Jenness
=for bad =for bad
Bad values are excluded from the search. If all pixels Bad values are excluded from the search. If all pixels
are bad then the output is set bad. are bad then the output is set bad.
=cut =cut
#line 463 "Image2D.pm" #line 459 "Image2D.pm"
#line 951 "/home/osboxes/pdl-code/blib/lib/PDL/PP.pm" #line 960 "/home/osboxes/pdl-code/blib/lib/PDL/PP.pm"
*max2d_ind = \&PDL::max2d_ind; *max2d_ind = \&PDL::max2d_ind;
#line 470 "Image2D.pm" #line 466 "Image2D.pm"
#line 949 "/home/osboxes/pdl-code/blib/lib/PDL/PP.pm" #line 958 "/home/osboxes/pdl-code/blib/lib/PDL/PP.pm"
=head2 centroid2d =head2 centroid2d
=for sig =for sig
Signature: (im(m,n); x(); y(); box(); [o]xcen(); [o]ycen()) Signature: (im(m,n); x(); y(); box(); [o]xcen(); [o]ycen())
=for ref =for ref
Refine a list of object positions in 2D image by centroiding in a box Refine a list of object positions in 2D image by centroiding in a box
skipping to change at line 404 skipping to change at line 400
C<$box> is the full-width of the box, i.e. the window C<$box> is the full-width of the box, i.e. the window
is C<+/- $box/2>. is C<+/- $box/2>.
=for bad =for bad
Bad pixels are excluded from the centroid calculation. If all elements are Bad pixels are excluded from the centroid calculation. If all elements are
bad (or the pixel sum is 0 - but why would you be centroiding bad (or the pixel sum is 0 - but why would you be centroiding
something with negatives in...) then the output values are set bad. something with negatives in...) then the output values are set bad.
=cut =cut
#line 501 "Image2D.pm" #line 497 "Image2D.pm"
#line 951 "/home/osboxes/pdl-code/blib/lib/PDL/PP.pm" #line 960 "/home/osboxes/pdl-code/blib/lib/PDL/PP.pm"
*centroid2d = \&PDL::centroid2d; *centroid2d = \&PDL::centroid2d;
#line 508 "Image2D.pm" #line 504 "Image2D.pm"
#line 803 "image2d.pd" #line 798 "image2d.pd"
=head2 crop =head2 crop
=for ref =for ref
Return bounding box of given mask in an C<indx> ndarray, so it can broadcast. Return bounding box of given mask in an C<indx> ndarray, so it can broadcast.
Use other operations (such as L<PDL::Bad/isgood>, or Use other operations (such as L<PDL::Bad/isgood>, or
L<PDL::Primitive/eqvec> with a colour vector) to create a mask suitable L<PDL::Primitive/eqvec> with a colour vector) to create a mask suitable
for your application. for your application.
skipping to change at line 439 skipping to change at line 435
sub PDL::crop { sub PDL::crop {
my ($mask) = @_; my ($mask) = @_;
$mask->xchg(0,1)->orover->_which_int(my $out = null, null); $mask->xchg(0,1)->orover->_which_int(my $out = null, null);
$out->badflag(1); $out->badvalue(-1); $out->badflag(1); $out->badvalue(-1);
my ($x1, $x2) = $out->minmaximum; my ($x1, $x2) = $out->minmaximum;
$mask->orover->_which_int($out = null, null); $mask->orover->_which_int($out = null, null);
$out->badflag(1); $out->badvalue(-1); $out->badflag(1); $out->badvalue(-1);
my ($y1, $y2) = $out->minmaximum; my ($y1, $y2) = $out->minmaximum;
$x1->cat($x2, $y1, $y2)->mv(-1,0); $x1->cat($x2, $y1, $y2)->mv(-1,0);
} }
#line 540 "Image2D.pm" #line 536 "Image2D.pm"
#line 833 "image2d.pd" #line 828 "image2d.pd"
=head2 cc8compt =head2 cc8compt
=for ref =for ref
Connected 8-component labeling of a binary image. Connected 8-component labeling of a binary image.
Connected 8-component labeling of 0,1 image - i.e. find separate Connected 8-component labeling of 0,1 image - i.e. find separate
segmented objects and fill object pixels with object number. segmented objects and fill object pixels with object number.
8-component labeling includes all neighboring pixels. 8-component labeling includes all neighboring pixels.
skipping to change at line 484 skipping to change at line 480
sub PDL::cc8compt{ sub PDL::cc8compt{
return ccNcompt(shift,8); return ccNcompt(shift,8);
} }
*cc8compt = \&PDL::cc8compt; *cc8compt = \&PDL::cc8compt;
sub PDL::cc4compt{ sub PDL::cc4compt{
return ccNcompt(shift,4); return ccNcompt(shift,4);
} }
*cc4compt = \&PDL::cc4compt; *cc4compt = \&PDL::cc4compt;
#line 588 "Image2D.pm" #line 584 "Image2D.pm"
#line 949 "/home/osboxes/pdl-code/blib/lib/PDL/PP.pm" #line 958 "/home/osboxes/pdl-code/blib/lib/PDL/PP.pm"
=head2 ccNcompt =head2 ccNcompt
=for sig =for sig
Signature: (a(m,n); int+ [o]b(m,n); int con) Signature: (a(m,n); int+ [o]b(m,n); int con)
=for ref =for ref
Connected component labeling of a binary image. Connected component labeling of a binary image.
skipping to change at line 518 skipping to change at line 514
$segmented2 = ccNcompt( $image > $threshold, 8); $segmented2 = ccNcompt( $image > $threshold, 8);
where the second parameter specifies the connectivity (4 or 8) of the labeling. where the second parameter specifies the connectivity (4 or 8) of the labeling.
=for bad =for bad
ccNcompt ignores the bad-value flag of the input ndarrays. ccNcompt ignores the bad-value flag of the input ndarrays.
It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
=cut =cut
#line 631 "Image2D.pm" #line 627 "Image2D.pm"
#line 951 "/home/osboxes/pdl-code/blib/lib/PDL/PP.pm" #line 960 "/home/osboxes/pdl-code/blib/lib/PDL/PP.pm"
*ccNcompt = \&PDL::ccNcompt; *ccNcompt = \&PDL::ccNcompt;
#line 638 "Image2D.pm" #line 634 "Image2D.pm"
#line 1002 "image2d.pd" #line 997 "image2d.pd"
=head2 polyfill =head2 polyfill
=for ref =for ref
fill the area of the given polygon with the given colour. fill the area of the given polygon with the given colour.
This function works inplace, i.e. modifies C<im>. This function works inplace, i.e. modifies C<im>.
=for usage =for usage
skipping to change at line 579 skipping to change at line 575
} }
else else
{ {
PDL::polyfill_pp($im,$ps,$colour); PDL::polyfill_pp($im,$ps,$colour);
} }
return $im; return $im;
} }
*polyfill = \&PDL::polyfill; *polyfill = \&PDL::polyfill;
#line 696 "Image2D.pm" #line 692 "Image2D.pm"
#line 1059 "image2d.pd" #line 1054 "image2d.pd"
=head2 pnpoly =head2 pnpoly
=for ref =for ref
'points in a polygon' selection from a 2-D ndarray 'points in a polygon' selection from a 2-D ndarray
=for usage =for usage
$mask = $img->pnpoly($ps); $mask = $img->pnpoly($ps);
skipping to change at line 660 skipping to change at line 656
my $testy = PDL::Core::topdl($ty)->dummy(0); my $testy = PDL::Core::topdl($ty)->dummy(0);
my $vertxj = PDL::Core::topdl($vertx)->rotate(1); my $vertxj = PDL::Core::topdl($vertx)->rotate(1);
my $vertyj = PDL::Core::topdl($verty)->rotate(1); my $vertyj = PDL::Core::topdl($verty)->rotate(1);
my $mask = ( ($verty>$testy) == ($vertyj>$testy) ); my $mask = ( ($verty>$testy) == ($vertyj>$testy) );
my $c = sumover( ! $mask & ( $testx < ($vertxj-$vertx) * ($testy-$verty) my $c = sumover( ! $mask & ( $testx < ($vertxj-$vertx) * ($testy-$verty)
/ ($vertyj-$verty+$mask) + $vertx) ) % 2; / ($vertyj-$verty+$mask) + $vertx) ) % 2;
return $c; return $c;
} }
*pnpoly = \&PDL::pnpoly; *pnpoly = \&PDL::pnpoly;
#line 780 "Image2D.pm" #line 776 "Image2D.pm"
#line 1142 "image2d.pd" #line 1137 "image2d.pd"
=head2 polyfillv =head2 polyfillv
=for ref =for ref
return the (dataflowed) area of an image described by a polygon return the (dataflowed) area of an image described by a polygon
=for usage =for usage
polyfillv($im,$ps,[\%options]); polyfillv($im,$ps,[\%options]);
skipping to change at line 714 skipping to change at line 710
my $parsed = PDL::Options->new({'Method' => undef}); my $parsed = PDL::Options->new({'Method' => undef});
$parsed->options($opt); $parsed->options($opt);
return $im->where(PDL::pnpoly_pp($im, $ps)) if $parsed->current-> {'Method'} eq 'pnpoly'; return $im->where(PDL::pnpoly_pp($im, $ps)) if $parsed->current-> {'Method'} eq 'pnpoly';
} }
my $msk = zeroes(long,$im->dims); my $msk = zeroes(long,$im->dims);
PDL::polyfill_pp($msk, $ps, 1); PDL::polyfill_pp($msk, $ps, 1);
return $im->where($msk); return $im->where($msk);
} }
*polyfillv = \&PDL::polyfillv; *polyfillv = \&PDL::polyfillv;
#line 837 "Image2D.pm" #line 833 "Image2D.pm"
#line 949 "/home/osboxes/pdl-code/blib/lib/PDL/PP.pm" #line 958 "/home/osboxes/pdl-code/blib/lib/PDL/PP.pm"
=head2 rot2d =head2 rot2d
=for sig =for sig
Signature: (im(m,n); float angle(); bg(); int aa(); [o] om(p,q)) Signature: (im(m,n); float angle(); bg(); int aa(); [o] om(p,q))
=for ref =for ref
rotate an image by given C<angle> rotate an image by given C<angle>
skipping to change at line 756 skipping to change at line 752
L<PDL::Transform> offers a more general interface to L<PDL::Transform> offers a more general interface to
distortions, including rotation, with various types of sampling; but distortions, including rotation, with various types of sampling; but
rot2d is faster. rot2d is faster.
=for bad =for bad
rot2d ignores the bad-value flag of the input ndarrays. rot2d ignores the bad-value flag of the input ndarrays.
It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
=cut =cut
#line 887 "Image2D.pm" #line 883 "Image2D.pm"
#line 951 "/home/osboxes/pdl-code/blib/lib/PDL/PP.pm" #line 960 "/home/osboxes/pdl-code/blib/lib/PDL/PP.pm"
*rot2d = \&PDL::rot2d; *rot2d = \&PDL::rot2d;
#line 894 "Image2D.pm" #line 890 "Image2D.pm"
#line 949 "/home/osboxes/pdl-code/blib/lib/PDL/PP.pm" #line 958 "/home/osboxes/pdl-code/blib/lib/PDL/PP.pm"
=head2 bilin2d =head2 bilin2d
=for sig =for sig
Signature: (Int(n,m); O(q,p)) Signature: (Int(n,m); O(q,p))
=for ref =for ref
Bilinearly maps the first ndarray in the second. The Bilinearly maps the first ndarray in the second. The
interpolated values are actually added to the second interpolated values are actually added to the second
ndarray which is supposed to be larger than the first one. ndarray which is supposed to be larger than the first one.
=for bad =for bad
bilin2d ignores the bad-value flag of the input ndarrays. bilin2d ignores the bad-value flag of the input ndarrays.
It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
=cut =cut
#line 924 "Image2D.pm" #line 920 "Image2D.pm"
#line 951 "/home/osboxes/pdl-code/blib/lib/PDL/PP.pm" #line 960 "/home/osboxes/pdl-code/blib/lib/PDL/PP.pm"
*bilin2d = \&PDL::bilin2d; *bilin2d = \&PDL::bilin2d;
#line 931 "Image2D.pm" #line 927 "Image2D.pm"
#line 949 "/home/osboxes/pdl-code/blib/lib/PDL/PP.pm" #line 958 "/home/osboxes/pdl-code/blib/lib/PDL/PP.pm"
=head2 rescale2d =head2 rescale2d
=for sig =for sig
Signature: (Int(m,n); O(p,q)) Signature: (Int(m,n); O(p,q))
=for ref =for ref
The first ndarray is rescaled to the dimensions of the second The first ndarray is rescaled to the dimensions of the second
skipping to change at line 815 skipping to change at line 811
tracking, consider using L<PDL::Transform::map|PDL::Transform/map> tracking, consider using L<PDL::Transform::map|PDL::Transform/map>
instead: it does these things, at some speed penalty compared to instead: it does these things, at some speed penalty compared to
rescale2d. rescale2d.
=for bad =for bad
rescale2d ignores the bad-value flag of the input ndarrays. rescale2d ignores the bad-value flag of the input ndarrays.
It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
=cut =cut
#line 966 "Image2D.pm" #line 962 "Image2D.pm"
#line 951 "/home/osboxes/pdl-code/blib/lib/PDL/PP.pm" #line 960 "/home/osboxes/pdl-code/blib/lib/PDL/PP.pm"
*rescale2d = \&PDL::rescale2d; *rescale2d = \&PDL::rescale2d;
#line 973 "Image2D.pm" #line 969 "Image2D.pm"
#line 1459 "image2d.pd" #line 1454 "image2d.pd"
=head2 fitwarp2d =head2 fitwarp2d
=for ref =for ref
Find the best-fit 2D polynomial to describe Find the best-fit 2D polynomial to describe
a coordinate transformation. a coordinate transformation.
=for usage =for usage
skipping to change at line 851 skipping to change at line 847
C<$px> and C<$py> are C<np> by C<np> element ndarrays which describe C<$px> and C<$py> are C<np> by C<np> element ndarrays which describe
a polynomial mapping (of order C<np-1>) a polynomial mapping (of order C<np-1>)
from the I<output> C<(u,v)> image to the I<input> C<(x,y)> image: from the I<output> C<(u,v)> image to the I<input> C<(x,y)> image:
x = sum(j=0,np-1) sum(i=0,np-1) px(i,j) * u^i * v^j x = sum(j=0,np-1) sum(i=0,np-1) px(i,j) * u^i * v^j
y = sum(j=0,np-1) sum(i=0,np-1) py(i,j) * u^i * v^j y = sum(j=0,np-1) sum(i=0,np-1) py(i,j) * u^i * v^j
The transformation is returned for the reverse direction (ie The transformation is returned for the reverse direction (ie
output to input image) since that is what is required by the output to input image) since that is what is required by the
L<warp2d()|/warp2d> routine. The L<applywarp2d()|/applywarp2d> L</warp2d> routine. The L</applywarp2d>
routine can be used to convert a set of C<$u,$v> points given routine can be used to convert a set of C<$u,$v> points given
C<$px> and C<$py>. C<$px> and C<$py>.
Options: Options:
=for options =for options
FIT - which terms to fit? default ones(byte,$nf,$nf) FIT - which terms to fit? default ones(byte,$nf,$nf)
=begin comment =begin comment
skipping to change at line 978 skipping to change at line 974
=for ref =for ref
Transform a set of points using a 2-D polynomial mapping Transform a set of points using a 2-D polynomial mapping
=for usage =for usage
( $x, $y ) = applywarp2d( $px, $py, $u, $v ) ( $x, $y ) = applywarp2d( $px, $py, $u, $v )
Convert a set of points (stored in 1D ndarrays C<$u,$v>) Convert a set of points (stored in 1D ndarrays C<$u,$v>)
to C<$x,$y> using the 2-D polynomial with coefficients stored in C<$px> to C<$x,$y> using the 2-D polynomial with coefficients stored in C<$px>
and C<$py>. See L<fitwarp2d()|/fitwarp2d> and C<$py>. See L</fitwarp2d>
for more information on the format of C<$px> and C<$py>. for more information on the format of C<$px> and C<$py>.
=cut =cut
# use SVD to fit data. Assuming no errors. # use SVD to fit data. Assuming no errors.
=pod =pod
=begin comment =begin comment
skipping to change at line 1245 skipping to change at line 1241
# #
my $mat = _mkbasis( ones(byte,$nf,$nf), $npts, $u, $v ); my $mat = _mkbasis( ones(byte,$nf,$nf), $npts, $u, $v );
my $x = reshape( $mat x $px->clump(-1)->transpose(), $npts ); my $x = reshape( $mat x $px->clump(-1)->transpose(), $npts );
my $y = reshape( $mat x $py->clump(-1)->transpose(), $npts ); my $y = reshape( $mat x $py->clump(-1)->transpose(), $npts );
return ( $x, $y ); return ( $x, $y );
} # sub: applywarp2d } # sub: applywarp2d
*applywarp2d = \&PDL::applywarp2d; *applywarp2d = \&PDL::applywarp2d;
#line 1402 "Image2D.pm" #line 1398 "Image2D.pm"
#line 1894 "image2d.pd" #line 958 "/home/osboxes/pdl-code/blib/lib/PDL/PP.pm"
=head2 warp2d =head2 warp2d
=for sig =for sig
Signature: (img(m,n); double px(np,np); double py(np,np); [o] warp(m,n); { opt ions }) Signature: (img(m,n); ldouble px(np,np); ldouble py(np,np); [o] warp(m,n); ldo uble [t] poly(np); ldouble [t] kernel(ns); char *kernel_type; double noval; int nsamples => ns)
=for ref =for ref
Warp a 2D image given a polynomial describing the I<reverse> mapping. Warp a 2D image given a polynomial describing the I<reverse> mapping.
=for usage =for usage
$out = warp2d( $img, $px, $py, { options } ); $out = warp2d( $img, $px, $py, { options } );
Apply the polynomial transformation encoded in the C<$px> and Apply the polynomial transformation encoded in the C<$px> and
C<$py> ndarrays to warp the input image C<$img> into the output C<$py> ndarrays to warp the input image C<$img> into the output
image C<$out>. image C<$out>.
The format for the polynomial transformation is described in The format for the polynomial transformation is described in
the documentation for the L<fitwarp2d()|/fitwarp2d> routine. the documentation for the L</fitwarp2d> routine.
At each point C<x,y>, the closest 16 pixel values are combined At each point C<x,y>, the closest 16 pixel values are combined
with an interpolation kernel to calculate the value at C<u,v>. with an interpolation kernel to calculate the value at C<u,v>.
The interpolation is therefore done in the image, rather than The interpolation is therefore done in the image, rather than
Fourier, domain. Fourier, domain.
By default, a C<tanh> kernel is used, but this can be changed By default, a C<tanh> kernel is used, but this can be changed
using the C<KERNEL> option discussed below using the C<KERNEL> option discussed below
(the choice of kernel depends on the frequency content of the input image). (the choice of kernel depends on the frequency content of the input image).
The routine is based on the C<warping> command from The routine is based on the C<warping> command from
skipping to change at line 1313 skipping to change at line 1309
The options are: The options are:
=for options =for options
KERNEL - default value is tanh KERNEL - default value is tanh
NOVAL - default value is 0 NOVAL - default value is 0
C<KERNEL> is used to specify which interpolation kernel to use C<KERNEL> is used to specify which interpolation kernel to use
(to see what these kernels look like, use the (to see what these kernels look like, use the
L<warp2d_kernel()|/warp2d_kernel> routine). L</warp2d_kernel> routine).
The options are: The options are:
=over 4 =over 4
=item tanh =item tanh
Hyperbolic tangent: the approximation of an ideal box filter by the Hyperbolic tangent: the approximation of an ideal box filter by the
product of symmetric tanh functions. product of symmetric tanh functions.
=item sinc =item sinc
skipping to change at line 1363 skipping to change at line 1359
=item hamming =item hamming
This kernel uses the same C<H(x)> as the Hann filter, but with This kernel uses the same C<H(x)> as the Hann filter, but with
C<a = 0.54>. C<a = 0.54>.
=back =back
C<NOVAL> gives the value used to indicate that a pixel in the C<NOVAL> gives the value used to indicate that a pixel in the
output image does not map onto one in the input image. output image does not map onto one in the input image.
=for bad
warp2d ignores the bad-value flag of the input ndarrays.
It will set the bad-value flag of all output ndarrays if the flag is set for any
of the input ndarrays.
=cut =cut
#line 1528 "Image2D.pm"
#line 959 "/home/osboxes/pdl-code/blib/lib/PDL/PP.pm"
# support routine # support routine
{ {
my %warp2d = map { ($_,1) } qw( tanh sinc sinc2 lanczos hamming hann ); my %warp2d = map { ($_,1) } qw( tanh sinc sinc2 lanczos hamming hann );
# note: convert to lower case # note: convert to lower case
sub _check_kernel ($$) { sub _check_kernel ($$) {
my $kernel = lc shift; my $kernel = lc shift;
my $code = shift; my $code = shift;
barf "Unknown kernel $kernel sent to $code\n" . barf "Unknown kernel $kernel sent to $code\n" .
"\tmust be one of [" . join(',',keys %warp2d) . "]\n" "\tmust be one of [" . join(',',keys %warp2d) . "]\n"
unless exists $warp2d{$kernel}; unless exists $warp2d{$kernel};
return $kernel; return $kernel;
} }
} }
#line 1539 "Image2D.pm"
#line 950 "/home/osboxes/pdl-code/blib/lib/PDL/PP.pm"
sub PDL::warp2d { sub PDL::warp2d {
my $opts = PDL::Options->new( { KERNEL => "tanh", NOVAL => 0 } ); my $opts = PDL::Options->new( { KERNEL => "tanh", NOVAL => 0 } );
$opts->options( pop(@_) ) if ref($_[$#_]) eq "HASH"; $opts->options( pop(@_) ) if ref($_[$#_]) eq "HASH";
die "Usage: warp2d( in(m,n), px(np,np); py(np,np); [o] out(m,n), {Options} ) " die "Usage: warp2d( in(m,n), px(np,np); py(np,np); [o] out(m,n), {Options} ) "
if $#_<2 || $#_>3; if $#_<2 || $#_>3;
my $img = shift; my $img = shift;
my $px = shift; my $px = shift;
my $py = shift; my $py = shift;
my $out = $#_ == -1 ? PDL->null() : shift; my $out = $#_ == -1 ? PDL->null() : shift;
# safety checks # safety checks
my $copt = $opts->current(); my $copt = $opts->current();
my $kernel = _check_kernel( $$copt{KERNEL}, "warp2d" ); my $kernel = _check_kernel( $$copt{KERNEL}, "warp2d" );
&PDL::_warp2d_int( $img, $px, $py, $out, $kernel, $$copt{NOVAL}, _get_kernel
&PDL::_warp2d_int( $img, $px, $py, $out, $kernel, $$copt{NOVAL} ); _size() );
return $out; return $out;
} }
#line 1565 "Image2D.pm" #line 1563 "Image2D.pm"
#line 951 "/home/osboxes/pdl-code/blib/lib/PDL/PP.pm" #line 960 "/home/osboxes/pdl-code/blib/lib/PDL/PP.pm"
*warp2d = \&PDL::warp2d; *warp2d = \&PDL::warp2d;
#line 1572 "Image2D.pm" #line 1570 "Image2D.pm"
#line 2199 "image2d.pd" #line 958 "/home/osboxes/pdl-code/blib/lib/PDL/PP.pm"
=head2 warp2d_kernel =head2 warp2d_kernel
=for sig
Signature: ([o] x(n); [o] k(n); ldouble [t] kernel(n); char *name; PDL_Indx ns
ize => n)
=for ref =for ref
Return the specified kernel, as used by L</warp2d> Return the specified kernel, as used by L</warp2d>
=for usage =for usage
( $x, $k ) = warp2d_kernel( $name ) ( $x, $k ) = warp2d_kernel( $name )
The valid values for C<$name> are the same as the C<KERNEL> option The valid values for C<$name> are the same as the C<KERNEL> option
of L<warp2d()|/warp2d>. of L</warp2d>.
=for example =for example
line warp2d_kernel( "hamming" ); line warp2d_kernel( "hamming" );
=for bad
warp2d_kernel ignores the bad-value flag of the input ndarrays.
It will set the bad-value flag of all output ndarrays if the flag is set for any
of the input ndarrays.
=cut =cut
#line 1598 "Image2D.pm" #line 1607 "Image2D.pm"
#line 950 "/home/osboxes/pdl-code/blib/lib/PDL/PP.pm" #line 959 "/home/osboxes/pdl-code/blib/lib/PDL/PP.pm"
sub PDL::warp2d_kernel ($) { sub PDL::warp2d_kernel ($) {
my $kernel = _check_kernel( shift, "warp2d_kernel" ); my $kernel = _check_kernel( shift, "warp2d_kernel" );
&PDL::_warp2d_kernel_int( my $x=PDL->null, my $k=PDL->null, $kernel, _get_ke
my $nelem = _get_kernel_size(); rnel_size() );
my $x = zeroes( $nelem );
my $k = zeroes( $nelem );
&PDL::_warp2d_kernel_int( $x, $k, $kernel );
return ( $x, $k ); return ( $x, $k );
# return _get_kernel( $kernel );
} }
*warp2d_kernel = \&PDL::warp2d_kernel;
#line 1619 "Image2D.pm" #line 1619 "Image2D.pm"
#line 951 "/home/osboxes/pdl-code/blib/lib/PDL/PP.pm" #line 960 "/home/osboxes/pdl-code/blib/lib/PDL/PP.pm"
*warp2d_kernel = \&PDL::warp2d_kernel; *warp2d_kernel = \&PDL::warp2d_kernel;
#line 1626 "Image2D.pm" #line 1626 "Image2D.pm"
#line 30 "image2d.pd" #line 31 "image2d.pd"
=head1 AUTHORS =head1 AUTHORS
Copyright (C) Karl Glazebrook 1997 with additions by Robin Williams Copyright (C) Karl Glazebrook 1997 with additions by Robin Williams
(rjrw@ast.leeds.ac.uk), Tim Jeness (timj@jach.hawaii.edu), (rjrw@ast.leeds.ac.uk), Tim Jenness (timj@jach.hawaii.edu),
and Doug Burke (burke@ifa.hawaii.edu). and Doug Burke (burke@ifa.hawaii.edu).
All rights reserved. There is no warranty. You are allowed All rights reserved. There is no warranty. You are allowed
to redistribute this software / documentation under certain to redistribute this software / documentation under certain
conditions. For details, see the file COPYING in the PDL conditions. For details, see the file COPYING in the PDL
distribution. If this file is separated from the PDL distribution, distribution. If this file is separated from the PDL distribution,
the copyright notice should be included in the file. the copyright notice should be included in the file.
=cut =cut
#line 1648 "Image2D.pm" #line 1648 "Image2D.pm"
 End of changes. 104 change blocks. 
121 lines changed or deleted 124 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)