PDL::Image2D - Miscellaneous 2D image processing functions
Miscellaneous 2D image processing functions - for want of anywhere else to put them
use PDL::Image2D;
Signature: (a(m,n); kern(p,q); [o]b(m,n); int opt)
2D convolution of an array with a kernel (smoothing)
For large kernels, using a FFT routine, such as PDL::FFT::fftconvolve(), will be quicker.
$new = conv2d $old, $kernel, {OPTIONS}
$smoothed = conv2d $image, ones(3,3), {Boundary => Reflect}
Boundary - controls what values are assumed for the image when kernel crosses its edge: => Default - periodic boundary conditions (i.e. wrap around axis) => Reflect - reflect at boundary => Truncate - truncate at boundary
Signature: (a(m,n); kern(p,q); [o]b(m,n); int opt)
2D median-convolution of an array with a kernel (smoothing)
Note: only points in the kernel >0 are included in the median, other points are weighted by the kernel value (medianing lots of zeroes is rather pointless)
$new = med2d $old, $kernel, {OPTIONS}
$smoothed = med2d $image, ones(3,3), {Boundary => Reflect}
Boundary - controls what values are assumed for the image when kernel crosses its edge: => Default - periodic boundary conditions (i.e. wrap around axis) => Reflect - reflect at boundary => Truncate - truncate at boundary
Signature: (a(m,n); int bad(m,n); [o]b(m,n))
patch bad pixels out of 2D images,
$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.
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
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
.
Signature: (a(m,n); [o]b(m,n))
Connected 8-component labeling of a binary image.
Connected 8-component labeling of 0,1 image - i.e. find seperate segmented objects and fill object pixels with object number
$segmented = cc8compt( $image > $threshold );
Signature: (int [o,nc] im(m,n); float ps(two=2,np); int col())
fill the area inside the given polygon with a given colour
This function works inplace, i.e. modifies im
.
return the (dataflown) area of an image within a polygon
# increment intensity in area bounded by $poly $im->polyfillv($pol)++; # legal in perl >= 5.6 # compute average intensity within area bounded by $poly $av = $im->polyfillv($poly)->avg;
Signature: (im(m,n); float angle(); bg(); int aa(); [o] om(p,q))
rotate an image by given angle
# rotate by 10.5 degrees with antialiasing, set missing values to 7 $rot = $im->rot2d(10.5,7,1);
This function rotates an image through an angle
between -90 and + 90
degrees. Uses/doesn't use antialiasing depending on the aa
flag.
Pixels outside the rotated image are set to bg
.
Code modified from pnmrotate (Copyright Jef Poskanzer) with an algorithm based on ``A Fast Algorithm for General Raster Rotation'' by Alan Paeth, Graphics Interface '86, pp. 77-81.
Use the rotnewsz
function to find out about the dimension of the
newly created image
($newcols,$newrows) = rotnewsz $oldn, $oldm, $angle;
Signature: (I(n,m); O(q,p))
Bilineary 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.
Signature: (I(n,m); O(q,p))
The first piddle is rescaled to the dimensions of the second (expandind or meaning values as needed) and then added to it.
Copyright (C) Karl Glazebrook 1997 with additions by Robin Williams (rjrw@ast.leeds.ac.uk) and Tim Jeness (timj@jach.hawaii.edu) 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.