med2df does not process bad values. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles.

box2d

Signature: (a(n,m); [o] b(n,m); int wx; int wy; int edgezero)

fast 2D boxcar average

$smoothim = $im->box2d($wx,$wy,$edgezero=1);

The edgezero argument controls if edge is set to zero (edgezero=1) or just keeps the original (unfiltered) values.

box2d should be updated to support similar edge options as conv2d and med2d etc.

Boxcar averaging is a pretty crude way of filtering. For serious stuff better filters are around (e.g., use conv2d with the appropriate kernel). On the other hand it is fast and computational cost grows only approximately linearly with window size.

box2d does not process bad values. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles.

patch2d

Signature: (a(m,n); int bad(m,n); [o]b(m,n))

patch bad pixels out of 2D images using a mask

$patched = patch2d $data, $bad;

$bad is a 2D mask array where 1=bad pixel 0=good pixel. Pixels are replaced by the average of their non-bad neighbours; if all neighbours are bad, the original data value is copied across.

patchbad2d

Signature: (a(m,n); [o]b(m,n))

patch bad pixels out of 2D images containing bad values

$patched = patchbad2d $data;

Pixels are replaced by the average of their non-bad neighbours; if all neighbours are bad, the output is set bad. If the input piddle contains no bad values, then a straight copy is performed (see patch2d).

patchbad2d handles bad values. The output piddle may contain bad values, depending on the pattern of bad values in the input piddle.

max2d_ind

Signature: (a(m,n); [o]val(); int [o]x(); int[o]y())

Return value/position of maximum value in 2D image

Contributed by Tim Jeness

Bad values are excluded from the search. If all pixels are bad then the output is set bad.

centroid2d

Signature: (im(m,n); x(); y(); box(); [o]xcen(); [o]ycen())

Refine a list of object positions in 2D image by centroiding in a box

$box is the full-width of the box, i.e. the window is +/- $box/2.

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 something with negatives in...) then the output values are set bad.

cc8compt

Connected 8-component labeling of a binary image.

Connected 8-component labeling of 0,1 image - i.e. find separate segmented objects and fill object pixels with object number. 8-component labeling includes all neighboring pixels. This is just a front-end to ccNcompt. See also cc4compt.

$segmented = cc8compt( $image > $threshold );

cc4compt

Connected 4-component labeling of a binary image.

Connected 4-component labeling of 0,1 image - i.e. find separate segmented objects and fill object pixels with object number. 4-component labling does not include the diagonal neighbors. This is just a front-end to ccNcompt. See also cc8compt.

where the second parameter specifies the connectivity (4 or 8) of the labeling.

ccNcompt ignores the bad-value flag of the input piddles. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles.

polyfill

fill the area of the given polygon with the given colour.

This function works inplace, i.e. modifies im.

polyfill($im,$ps,$colour,[\%options]);

The default method of determining which points lie inside of the polygon used is not as strict as the method used in pnpoly. Often, it includes vertices and edge points. Set the Method option to change this behaviour.

Method - Set the method used to determine which points lie in the polygon. => Default - internal PDL algorithm => pnpoly - use the pnpoly algorithm

# Make a convex 3x3 square of 1s in an image using the pnpoly algorithm
$ps = pdl([3,3],[3,6],[6,6],[6,3]);
polyfill($im,$ps,1,{'Method' =>'pnpoly'});

pnpoly

For a closed polygon determined by the sequence of points in {$px,$py} the output of pnpoly is a mask corresponding to whether or not each coordinate (x,y) in the set of test points, {$x,$y}, is in the interior of the polygon. This is the 'points in a polygon' algorithm from http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html and vectorized for PDL by Karl Glazebrook.

polyfillv

return the (dataflown) area of an image described by a polygon

polyfillv($im,$ps,[\%options]);

The default method of determining which points lie inside of the polygon used is not as strict as the method used in pnpoly. Often, it includes vertices and edge points. Set the Method option to change this behaviour.

Method - Set the method used to determine which points lie in the polygon. => Default - internal PDL algorithm => pnpoly - use the pnpoly algorithm

# increment intensity in area bounded by $poly using the pnpoly algorithm
$im->polyfillv($poly,{'Method'=>'pnpoly'})++; # legal in perl >= 5.6
# compute average intensity within area bounded by $poly using the default algorithm
$av = $im->polyfillv($poly)->avg;

Use the rotnewsz function to find out about the dimension of the newly created image

($newcols,$newrows) = rotnewsz $oldn, $oldm, $angle;

PDL::Transform offers a more general interface to distortions, including rotation, with various types of sampling; but rot2d is faster.

rot2d ignores the bad-value flag of the input piddles. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles.

bilin2d

Signature: (I(n,m); O(q,p))

Bilinearly maps the first piddle in the second. The interpolated values are actually added to the second piddle which is supposed to be larger than the first one.

bilin2d ignores the bad-value flag of the input piddles. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles.

rescale2d

Signature: (I(m,n); O(p,q))

The first piddle is rescaled to the dimensions of the second (expanding or meaning values as needed) and then added to it in place. Nothing useful is returned.

If you want photometric accuracy or automatic FITS header metadata tracking, consider using PDL::Transform::map instead: it does these things, at some speed penalty compared to rescale2d.

rescale2d ignores the bad-value flag of the input piddles. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles.

fitwarp2d

Find the best-fit 2D polynomial to describe a coordinate transformation.

( $px, $py ) = fitwarp2d( $x, $y, $u, $v, $nf. { options } )

Given a set of points in the output plane ($u,$v), find the best-fit (using singular-value decomposition) 2D polynomial to describe the mapping back to the image plane ($x,$y). The order of the fit is controlled by the $nf parameter (the maximum power of the polynomial is $nf - 1), and you can restrict the terms to fit using the FIT option.

$px and $py are np by np element piddles which describe a polynomial mapping (of order np-1) from the output(u,v) image to the input(x,y) image:

The transformation is returned for the reverse direction (ie output to input image) since that is what is required by the warp2d() routine. The applywarp2d() routine can be used to convert a set of $u,$v points given $px and $py.

FIT allows you to restrict which terms of the polynomial to fit: only those terms for which the FIT piddle evaluates to true will be evaluated. If a 2D piddle is sent in, then it is used for the x and y polynomials; otherwise $fit->slice(":,:,(0)") will be used for $px and $fit->slice(":,:,(1)") will be used for $py.

THRESH

Remove all singular values whose valus is less than THRESH times the largest singular value.

The number of points must be at least equal to the number of terms to fit ($nf*$nf points for the default value of FIT).

warp2d

Apply the polynomial transformation encoded in the $px and $py piddles to warp the input image $img into the output image $out.

The format for the polynomial transformation is described in the documentation for the fitwarp2d() routine.

At each point x,y, the closest 16 pixel values are combined with an interpolation kernel to calculate the value at u,v. The interpolation is therefore done in the image, rather than Fourier, domain. By default, a tanh kernel is used, but this can be changed using the KERNEL option discussed below (the choice of kernel depends on the frequency content of the input image).

The routine is based on the warping command from the Eclipse data-reduction package - see http://www.eso.org/eclipse/ - and for further details on image resampling see Wolberg, G., "Digital Image Warping", 1990, IEEE Computer Society Press ISBN 0-8186-8944-7).

Currently the output image is the same size as the input one, which means data will be lost if the transformation reduces the pixel scale. This will (hopefully) be changed soon.

AUTHORS

All rights reserved. There is no warranty. You are allowed to redistribute this software / documentation under certain conditions. For details, see the file COPYING in the PDL distribution. If this file is separated from the PDL distribution, the copyright notice should be included in the file.