"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "Libtmp/Image2D/image2d.pd" between
PDL-2.082.tar.gz and PDL-2.083.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.pd  (PDL-2.082):image2d.pd  (PDL-2.083)
skipping to change at line 60 skipping to change at line 60
# BEGIN INTERNAL FUNCTION DECLARATIONS # # BEGIN INTERNAL FUNCTION DECLARATIONS #
################################################# #################################################
pp_addhdr(' pp_addhdr('
void polyfill(PDL_Long *image, int wx, int wy, float *ps, int n, void polyfill(PDL_Long *image, int wx, int wy, float *ps, int n,
PDL_Long col, int *ierr); PDL_Long col, int *ierr);
'); ');
pp_def('polyfill_pp', pp_def('polyfill_pp',
HandleBad => 0, # a marker HandleBad => 0, # a marker
Pars => 'int [o,nc] im(m,n); float ps(two=2,np); int col()', Pars => 'int [io] im(m,n); float ps(two=2,np); int col()',
Code => 'int ierr = 0, nerr; Code => 'int ierr = 0, nerr;
broadcastloop %{ broadcastloop %{
polyfill($P(im), $SIZE(m), $SIZE(n), $P(ps), $SIZE(np), $col() , &nerr); polyfill($P(im), $SIZE(m), $SIZE(n), $P(ps), $SIZE(np), $col() , &nerr);
ierr = ierr < nerr ? nerr : ierr; ierr = PDLMAX(ierr, nerr);
%} %}
if (ierr) warn("errors during polygonfilling"); if (ierr) warn("errors during polygonfilling");
', ',
Doc => undef, Doc => undef,
PMFunc => '' PMFunc => ''
); );
my %pnpolyFields = ( my %pnpolyFields = (
'pnpoly_pp' => {'pars' => 'a(m,n); ps(k,l); int [o] msk(m,n)', 'special' => '$msk() = c;'}, 'pnpoly_pp' => {'pars' => 'a(m,n); ps(k,l); int [o] msk(m,n)', 'special' => '$msk() = c;'},
'pnpolyfill_pp' => {'pars' => '[o,nc] a(m,n); ps(k,l); int col()', 'speci al' => 'if(c) { $a() = $col(); }'} 'pnpolyfill_pp' => {'pars' => '[io] a(m,n); ps(k,l); int col()', 'special ' => 'if(c) { $a() = $col(); }'}
); );
for my $name (sort keys %pnpolyFields) { for my $name (sort keys %pnpolyFields) {
pp_def($name, pp_def($name,
HandleBad => 0, HandleBad => 0,
PMFunc => '', PMFunc => '',
Doc => undef, Doc => undef,
Pars => $pnpolyFields{$name}->{'pars'}, Pars => $pnpolyFields{$name}->{'pars'},
Code => ' Code => '
int i, j, c, nvert; int i, j, c, nvert;
skipping to change at line 762 skipping to change at line 762
BadDoc=><<'EOD', BadDoc=><<'EOD',
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.
EOD EOD
HandleBad => 1, HandleBad => 1,
Pars => 'im(m,n); x(); y(); box(); [o]xcen(); [o]ycen();', Pars => 'im(m,n); x(); y(); box(); [o]xcen(); [o]ycen();',
Code => ' Code => '
PDL_Indx i,j,i1,i2,j1,j2,m_size = $SIZE(m),n_size = $SIZE(n); PDL_Indx i,j,i1,i2,j1,j2,m_size = $SIZE(m),n_size = $SIZE(n);
PDL_LDouble sum,data,sumx,sumy; PDL_LDouble sum,data,sumx,sumy;
i1 = $x() - $box()/2; i1 = i1<0 ? 0 : i1; i1 = $x() - $box()/2; i1 = PDLMAX(i1, 0);
i2 = $x() + $box()/2; i2 = i2>=m_size ? m_size-1 : i2; i2 = $x() + $box()/2; i2 = PDLMIN(i2, m_size-1);
j1 = $y() - $box()/2; j1 = j1<0 ? 0 : j1; j1 = $y() - $box()/2; j1 = PDLMAX(j1, 0);
j2 = $y() + $box()/2; j2 = j2>=n_size ? n_size-1 : j2; j2 = $y() + $box()/2; j2 = PDLMIN(j2, n_size-1);
sum = sumx = sumy = 0; sum = sumx = sumy = 0;
for(j=j1; j<=j2; j++) { for(j=j1; j<=j2; j++) {
for(i=i1; i<=i2; i++) { for(i=i1; i<=i2; i++) {
data = $im(m=>i,n=>j); data = $im(m=>i,n=>j);
PDL_IF_BAD(if ( $ISGOODVAR(data,im) ),) { PDL_IF_BAD(if ( $ISGOODVAR(data,im) ),) {
sum += data; sum += data;
sumx += data*i; sumx += data*i;
sumy += data*j; sumy += data*j;
} }
} }
skipping to change at line 1269 skipping to change at line 1269
distortions, including rotation, with various types of sampling; but distortions, including rotation, with various types of sampling; but
rot2d is faster. rot2d is faster.
=cut =cut
EOD EOD
); );
pp_def('bilin2d', pp_def('bilin2d',
HandleBad => 0, HandleBad => 0,
Pars => 'Int(n,m); O(q,p)', Pars => 'Int(n,m); [io] O(q,p)',
Doc=><<'EOD', Doc=><<'EOD',
=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.
=cut
EOD EOD
,
GenericTypes => $A, GenericTypes => $A,
Code =>' Code =>'
PDL_Indx i,j,ii,jj,ii1,jj1,num; PDL_Indx i,j,ii,jj,ii1,jj1,num;
PDL_CLDouble x,y,dx,dy,y1,y2,y3,y4,t,u,sum; PDL_CLDouble x,y,dx,dy,y1,y2,y3,y4,t,u,sum;
if ($SIZE(q)>=$SIZE(n) && $SIZE(p)>=$SIZE(m)) { if ($SIZE(q)<$SIZE(n) || $SIZE(p)<$SIZE(m))
broadcastloop %{
dx = ((double) ($SIZE(n)-1)) / ($SIZE(q)-1);
dy = ((double) ($SIZE(m)-1)) / ($SIZE(p)-1);
for(i=0,x=0;i<$SIZE(q);i++,x+=dx) {
for(j=0,y=0;j<$SIZE(p);j++,y+=dy) {
ii = (int) floor(x);
if (ii>=($SIZE(n)-1)) ii = $SIZE(n)-2;
jj = (int) floor(y);
if (jj>=($SIZE(m)-1)) jj = $SIZE(m)-2;
ii1 = ii+1;
jj1 = jj+1;
y1 = $Int(n=>ii,m=>jj);
y2 = $Int(n=>ii1,m=>jj);
y3 = $Int(n=>ii1,m=>jj1);
y4 = $Int(n=>ii,m=>jj1);
t = x-ii;
u = y-jj;
$O(q=>i,p=>j) += (1-t)*(1-u)*y1 + t*(1-u)*y2 + t*u*y3 + (1-t)*u*y4;
}
}
%}
}
else {
$CROAK("the second matrix must be greater than first! (bilin2d)"); $CROAK("the second matrix must be greater than first! (bilin2d)");
}
broadcastloop %{
dx = ((double) ($SIZE(n)-1)) / ($SIZE(q)-1);
dy = ((double) ($SIZE(m)-1)) / ($SIZE(p)-1);
for(i=0,x=0;i<$SIZE(q);i++,x+=dx) {
for(j=0,y=0;j<$SIZE(p);j++,y+=dy) {
ii = (int) floor(x);
if (ii>=($SIZE(n)-1)) ii = $SIZE(n)-2;
jj = (int) floor(y);
if (jj>=($SIZE(m)-1)) jj = $SIZE(m)-2;
ii1 = ii+1;
jj1 = jj+1;
y1 = $Int(n=>ii,m=>jj);
y2 = $Int(n=>ii1,m=>jj);
y3 = $Int(n=>ii1,m=>jj1);
y4 = $Int(n=>ii,m=>jj1);
t = x-ii;
u = y-jj;
$O(q=>i,p=>j) += (1-t)*(1-u)*y1 + t*(1-u)*y2 + t*u*y3 + (1-t)*u*y4;
}
}
%}
'); ');
pp_def('rescale2d', pp_def('rescale2d',
HandleBad => 0, HandleBad => 0,
Pars => 'Int(m,n); O(p,q)', Pars => 'Int(m,n); [io] O(p,q)',
Doc=><<'EOD', Doc=><<'EOD',
=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
(expanding or meaning values as needed) and then added to it in place. (expanding or meaning values as needed) and then added to it in place.
Nothing useful is returned. Nothing useful is returned.
If you want photometric accuracy or automatic FITS header metadata If you want photometric accuracy or automatic FITS header metadata
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.
=cut
EOD EOD
,
GenericTypes => $A, GenericTypes => $A,
Code =>' Code =>'
PDL_Indx ix,iy,ox,oy,i,j,lx,ly,cx,cy,xx,yy,num; PDL_Indx ix,iy,ox,oy,i,j,lx,ly,cx,cy,xx,yy,num;
PDL_CLDouble kx,ky,temp; PDL_CLDouble kx,ky,temp;
ix = $SIZE(m); ix = $SIZE(m);
iy = $SIZE(n); iy = $SIZE(n);
ox = $SIZE(p); ox = $SIZE(p);
oy = $SIZE(q); oy = $SIZE(q);
if(ox >= ix && oy >= iy) { if(ox >= ix && oy >= iy) {
kx = ((PDL_CLDouble) (ox)) / (ix);
ky = ((PDL_CLDouble) (oy)) / (iy);
broadcastloop %{ broadcastloop %{
kx = ((double) (ox)) / (ix);
ky = ((double) (oy)) / (iy);
lx = 0; lx = 0;
for(i=0;i<ix;i++) { for(i=0;i<ix;i++) {
ly = 0; ly = 0;
for(j=0;j<iy;j++) { for(j=0;j<iy;j++) {
cx = rint((i+1)*kx)-1; cx = rint((i+1)*kx)-1;
cy = rint((j+1)*ky)-1; cy = rint((j+1)*ky)-1;
for(xx=lx;xx<=cx;xx++) for(xx=lx;xx<=cx;xx++)
for(yy=ly;yy<=cy;yy++) { for(yy=ly;yy<=cy;yy++) {
/* fprintf(stderr,"i: %d, j: %d, xx: %d, yy: %d\n",i,j,xx,yy); */ /* fprintf(stderr,"i: %d, j: %d, xx: %d, yy: %d\n",i,j,xx,yy); */
$O(p=>xx,q=>yy) += $Int(m=>i,n=>j); $O(p=>xx,q=>yy) += $Int(m=>i,n=>j);
} }
ly = cy + 1; ly = cy + 1;
} }
lx = cx + 1; lx = cx + 1;
} }
%} %}
} }
else if(ox < ix && oy < iy) { else if(ox < ix && oy < iy) {
kx = ((PDL_CLDouble) (ix)) / (ox);
ky = ((PDL_CLDouble) (iy)) / (oy);
broadcastloop %{ broadcastloop %{
kx = ((double) (ix)) / (ox);
ky = ((double) (iy)) / (oy);
lx = 0; lx = 0;
for(i=0;i<ox;i++) { for(i=0;i<ox;i++) {
ly = 0; ly = 0;
for(j=0;j<oy;j++) { for(j=0;j<oy;j++) {
cx = rint((i+1)*kx)-1; cx = rint((i+1)*kx)-1;
cy = rint((j+1)*ky)-1; cy = rint((j+1)*ky)-1;
temp = 0.0; temp = 0.0;
num = 0; num = 0;
for(xx=lx;xx<=cx;xx++) for(xx=lx;xx<=cx;xx++)
for(yy=ly;yy<=cy;yy++) { for(yy=ly;yy<=cy;yy++) {
skipping to change at line 1392 skipping to change at line 1380
num++; num++;
} }
$O(p=>i,q=>j) += temp/num; $O(p=>i,q=>j) += temp/num;
ly = cy + 1; ly = cy + 1;
} }
lx = cx + 1; lx = cx + 1;
} }
%} %}
} }
else if(ox >= ix && oy < iy) { else if(ox >= ix && oy < iy) {
kx = ((PDL_CLDouble) (ox)) / (ix);
ky = ((PDL_CLDouble) (iy)) / (oy);
broadcastloop %{ broadcastloop %{
kx = ((double) (ox)) / (ix);
ky = ((double) (iy)) / (oy);
lx = 0; lx = 0;
for(i=0;i<ix;i++) { for(i=0;i<ix;i++) {
ly = 0; ly = 0;
for(j=0;j<oy;j++) { for(j=0;j<oy;j++) {
cx = rint((i+1)*kx)-1; cx = rint((i+1)*kx)-1;
cy = rint((j+1)*ky)-1; cy = rint((j+1)*ky)-1;
temp = 0.0; temp = 0.0;
num = 0; num = 0;
for(yy=ly;yy<=cy;yy++) { for(yy=ly;yy<=cy;yy++) {
/* fprintf(stderr,"1 i: %d, j: %d, xx: %d, yy: %d\n",i,j,xx,yy); */ /* fprintf(stderr,"1 i: %d, j: %d, xx: %d, yy: %d\n",i,j,xx,yy); */
skipping to change at line 1419 skipping to change at line 1407
/* fprintf(stderr,"2 i: %d, j: %d, xx: %d, yy: %d\n",i,j,xx,yy); */ /* fprintf(stderr,"2 i: %d, j: %d, xx: %d, yy: %d\n",i,j,xx,yy); */
$O(p=>xx,q=>j) += temp/num; $O(p=>xx,q=>j) += temp/num;
} }
ly = cy + 1; ly = cy + 1;
} }
lx = cx + 1; lx = cx + 1;
} }
%} %}
} }
else if(ox < ix && oy >= iy) { else if(ox < ix && oy >= iy) {
kx = ((PDL_CLDouble) (ix)) / (ox);
ky = ((PDL_CLDouble) (oy)) / (iy);
broadcastloop %{ broadcastloop %{
kx = ((double) (ix)) / (ox);
ky = ((double) (oy)) / (iy);
lx = 0; lx = 0;
for(i=0;i<ox;i++) { for(i=0;i<ox;i++) {
ly = 0; ly = 0;
for(j=0;j<iy;j++) { for(j=0;j<iy;j++) {
cx = rint((i+1)*kx)-1; cx = rint((i+1)*kx)-1;
cy = rint((j+1)*ky)-1; cy = rint((j+1)*ky)-1;
temp = 0.0; temp = 0.0;
num = 0; num = 0;
for(xx=lx;xx<=cx;xx++) { for(xx=lx;xx<=cx;xx++) {
/* fprintf(stderr,"1 i: %d, j: %d, xx: %d, yy: %d\n",i,j,xx,yy); */ /* fprintf(stderr,"1 i: %d, j: %d, xx: %d, yy: %d\n",i,j,xx,yy); */
 End of changes. 22 change blocks. 
52 lines changed or deleted 40 lines changed or added

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