IPA - Image Processing Algorithms
IPA stands for Image Processing Algorithms and represents the library of image processing operators and functions. IPA is based on the Prima toolkit ( http://www.prima.eu.org ), which in turn is a perl-based graphic library. IPA is designed for solving image analysis and object recognition tasks in perl.
IPA works mostly with grayscale images, which can be loaded
or created by means of Prima toolkit. See the Prima::Image manpage for
the information about Prima::Image
class functionality.
IPA methods are grouped in several modules, that contain the
specific functions. The functions usually accept one or more
images and optional parameter hash. Each function has its own
set of parameters. If error occurs, the functions call die
,
so it is advisable to use eval
blocks around the calls.
A code that produces a binary thresholded image out of a 8-bit grayscale image is exemplified:
use Prima; use IPA; use IPA::Point; my $i = Prima::Image-> load('8-bit-grayscale.gif'); die "Cannot load:$@\n" if $@; my $binary = IPA::Point::threshold( $i, minvalue => 128);
The abbreviations for pixel types are used, derived from
the im::XXX
image type constants, as follows:
im::Byte - 8-bit unsigned integer im::Short - 16-bit signed integer im::Long - 32-bit signed integer im::Float - float im::Double - double im::Complex - complex float im::DCOmplex - complex double
Each function returns the newly created image object with the result of the operation, unless stated otherwise in API.
IPA::Point
module contains functions that perform single point
transformations and image arithmetic.
Single-point processing is a simple method of image enhancement. This technique determines a pixel value in the enhanced image dependent only on the value of the corresponding pixel in the input image. The process can be described with the mapping function
s = M(r)
where r
and s
are the pixel values in the input and output images, respectively.
Supported types: Byte, Short, Long.
Parameters:
Trunc
constants cut off the output values to the
bit maximum, for example, a result vector in 8-bit image [-5,0,100,300]
would be transformed to [0,0,100,255]. Scale
constants scale the whole
image without the cutoff; the previous example vector would be transformed
into [0,4,88,255]. The Abs
suffix shows whether the range calculation would
use the whole domain, including the negative values, or the absolute values
only.
conversionTruncAbs conversionTrunc conversionScale conversionScaleAbs
Default is conversionScale
.
combineMaxAbs - store the maximal absolute pixel value combineSignedMaxAbs - compute the maximal absolute value, but store its original ( before abs()) value combineSumAbs - store the sum of absolute pixel values combineSum - store the sum of pixel values combineSqrt - store the square root of the sum of the squares of the pixel values
Default is combineSum
.
conversionType
parameter and performs no conversion.
If set to true value, the conversion step is omitted.
Default is 0.
minvalue
and maxvalue
.
The pixels, that are below minvalue
and above maxvalue
,
are mapped to value 0; the other values mapped to 255.
Supported types: Byte
origGamma
and destGamma
.
Supported types: Byte
lookup
array
of 256 integer values. Example:
IPA::Point::remap( $i, lookup => [ (0) x 128, (255) x 127]);
is an equivalent of
IPA::Point::threshold( $i, minvalue => 128);
Supported types: 8-bit
conversionType
and rawOutput
see combine.
Supported types: Byte
test
, and
assigns the resulting pixel with either match
or mismatch
value.
All test
, match
, and mismatch
scalars can be either integers
( in which case mask
operator is similar to threshold ),
or image objects. If the image objects passed, they must be of the same
dimensions and bit depth as IMAGE.
Supported types: Byte, Short, Long.
Supported types: Byte, Short, Long, 64-bit integer.
Supported types: Byte
Contains functions that operate in the vicinity of a pixel, and produce image where every pixel is dependant on the values of the source pixel and the values of its neighbors. The process can be described with the mapping function
|r(i,j),r(i+1,j)...| s = M |... | |r(j+1,i) ... |
where r
and s
are the pixel values in the input and output images, respectively.
Supported types: Byte
Supported types: Byte
Parameters:
| (-1,1) (0,1) (1,1) | | (-1,0) (0,0) (1,0) | | (-1,-1)(0,-1)(1,-1)|
Then the constants mask the following points:
sobelRow - (-1,0),(1,0) sobelColumn - (0,1),(0,-1) sobelNESW - (1,1),(-1,-1) sobelNWSE - (-1,1),(1,-1)
(0,0) point is always masked.
divisor
value after the kernel convolution is applied.
conversionType
and <combineType> parameters described in combine.
Supported types: Byte
Supported types: Byte
Supported types: Byte
matrix
.
Supported types: Byte
Parameters:
|0 1 2| |3 4 5| |6 7 8|
edgecolor
value
is used to substitute the pixels outside the image.
expandEdges
parameter is set to 1.
divisor
value after the kernel convolution is applied.
w
and h
.
method
. The only implemented
method is average-based region grow ( 'ave' string constant ). Its only
parameter is threshold
, integer value of the balance merger function.
Supported types: Byte
Contains methods that produce images, where every pixel is a function of all pixels in the source image. The process can be described with the mapping function
s = M(R)
where s
is the pixel value in the output images, and R is the source image.
gradient
image.
The unclosed shapes converted to the closed if the gradient spot between the
suspected dents falls under maxlen
maximal length increment, mingradient
the minimal gradient value and the edge is longer than minedgelen
.
Supported types: Byte
Parameters:
Supported types: Byte
Parameters:
minArea
and more than maxArea
. The other parameters are identical to those passed to fill_holes.
The parameters are identical to those passed to fill_holes.
Supported types: Byte
See also the IPA::Region manpage.
inverse
boolean flag )
fast Fourier transform. IMAGE must have dimensions of power of 2.
The resulted image is always of DComplex type.
Supported types: all
inverse
boolean flag )
fast Fourier transform. If IMAGE dimensions not of power of 2, then
IMAGE is scaled up to the closest power of 2, and the result is scaled
back to the original dimensions.
The resulted image is always of DComplex type.
Supported types: all
Supported types: all
Parameters:
spatial
parameter set to true ).
The resulted image is always of DComplex type.
Supported types: all
The parameters are same as those passed to band_filter.
Quote from http://www.dai.ed.ac.uk/HIPR2/morops.htm:
Morphological operators often take a binary image and a structuring element as input and combine them using a set operator (intersection, union, inclusion, complement). They process objects in the input image based on characteristics of its shape, which are encoded in the structuring element.
Usually, the structuring element is sized 3x3 and has its origin at the center pixel. It is shifted over the image and at each pixel of the image its elements are compared with the set of the underlying pixels. If the two sets of elements match the condition defined by the set operator (e.g. if the set of pixels in the structuring element is a subset of the underlying image pixels), the pixel underneath the origin of the structuring element is set to a pre-defined value (0 or 1 for binary images). A morphological operator is therefore defined by its structuring element and the applied set operator.
Morphological operators can also be applied to graylevel images, e.g. to reduce noise or to brighten the image.
lookup
LUT string ( look-up table ) to image and returns
the convolution result ( hit-and-miss transform). Each byte of lookup
is a set
of bits, each corresponding to the 3x3 kernel index:
|4 3 2| |5 0 1| |6 7 8|
Thus, for example, the X-shape would be represented by offset 2**0 + 2**2 + 2**4 + 2**6 + 2**8 = 341 .
The byte value, corresponding to the offset in lookup
string is stored in the output
image.
IPA::Morphology
defines several basic LUT transforms, which can be invoked by the following
code:
IPA::Morphological::bw_METHOD( $image);
or its alternative
IPA::Morphology::BWTransform( $image, lookup => $IPA::Morphology::transform_luts{METHOD}->());
Where METHOD is one of the followng string constants:
Supported types: Byte
neighborhood
determines whether the algorithm assumes 4- or 8- pixel connectivity.
Supported types: Byte, Short, Long, Float, Double
neighborhood
determines whether the algorithm assumes 4- or 8- pixel connectivity.
Supported types: Byte, Short, Long, Float, Double
neighborhood
determines whether the algorithm assumes 4- or 8- pixel connectivity.
Supported types: Byte, Short, Long, Float, Double
neighborhood
determines whether the algorithm assumes 4- or 8- pixel connectivity.
Supported types: Byte, Short, Long, Float, Double
neighborhood
determines whether the algorithm assumes 4- or 8- pixel connectivity.
Supported types: Byte, Short, Long, Float, Double
inPlace
is set,
IMAGE1 contains the result.
Supported types: Byte, Short, Long, Float, Double
neighborhood
.
Supported types: Byte
If boolean inPlace
flag is set, IMAGE2 contains the result.
neighborhood
determines whether the algorithm assumes 4- or 8- pixel connectivity.
Supported types: Byte, Short, Long, Float, Double
Supported types: Byte
Contains function for mapping pixels from one location to another
type
,
which can be one of the following constants:
IPA::Geometry::vertical IPA::Geometry::horizontal
Supported types: all
where
, which is one of the following constants
IPA::Geometry::vertical IPA::Geometry::horizontal
by the offset, specified by integer size
.
Supported types: all, except that the horizontal transformation does not support 1- and 4- bit images.
Contains miscellaneous helper routines.
'rgb'
only. Returns channels as anonymous
array of image objects.
Supported types: RGB
Supported types: 8-bit
Anton Berezin <tobez@tobez.org>, Vadim Belman <voland@lflat.org>, Dmitry Karasik <dmitry@karasik.eu.org>