1# $Id$ 2package IPA::Local; 3 4use strict; 5require Exporter; 6 7use constant sobelColumn => 1; 8use constant sobelRow => 2; 9use constant sobelNWSE => 4; 10use constant sobelNESW => 8; 11 12use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); 13@ISA = qw(Exporter); 14$VERSION = '0.02'; 15@EXPORT = qw(); 16@EXPORT_OK = qw(crispening 17 sobel 18 GEF 19 SDEF 20 deriche 21 filter3x3 22 median 23 unionFind 24 hysteresis 25 gaussian 26 laplacian 27 gradients 28 canny 29 nms 30 scale 31 ridge 32 convolution 33 zerocross 34 ); 35%EXPORT_TAGS = (enhancement => [qw(crispening)], 36 edgedetect => [qw(sobel GEF SDEF deriche hysteresis canny)]); 37 381; 39 40__DATA__ 41 42=pod 43 44=head1 NAME 45 46IPA::Local - methods that produce images where every pixel is a function of pixels in the neighborhood 47 48=head1 DESCRIPTION 49 50Contains functions that operate in the vicinity of a pixel, and produce 51image where every pixel is dependant on the values of the source pixel 52and the values of its neighbors. 53The process can be described with the mapping function 54 55 |r(i,j),r(i+1,j)...| 56 s = M |... | 57 |r(j+1,i) ... | 58 59where C<r> and C<s> are the pixel values in the input and output images, respectively. 60 61=over 62 63=item crispening IMAGE 64 65Applies the crispening algorithm to IMAGE and returns the result. 66 67Supported types: Byte 68 69=item sobel IMAGE [ jobMask = sobelNWSE|sobelNESW, conversionType = conversionScaleAbs, combineType = combineMaxAbs, divisor = 1] 70 71Applies Sobel edge detector to IMAGE. 72 73Supported types: Byte 74 75Parameters: 76 77=over 78 79=item jobMask INTEGER 80 81Combination of the integer constants, that mask the pixels in Sobel 3x3 kernel. 82If the kernel is to be drawn as 83 84 | (-1,1) (0,1) (1,1) | 85 | (-1,0) (0,0) (1,0) | 86 | (-1,-1)(0,-1)(1,-1)| 87 88Then the constants mask the following points: 89 90 sobelRow - (-1,0),(1,0) 91 sobelColumn - (0,1),(0,-1) 92 sobelNESW - (1,1),(-1,-1) 93 sobelNWSE - (-1,1),(1,-1) 94 95(0,0) point is always masked. 96 97=item divisor INTEGER 98 99The resulting pixel value is divided to C<divisor> value after the kernel convolution is applied. 100 101=back 102 103C<conversionType> and <combineType> parameters described in L<combine>. 104 105=item GEF IMAGE [ a0 = 1.3, s = 0.7] 106 107Applies GEF algorithm ( first derivative operator for symmetric exponential filter) to IMAGE. 108 109Supported types: Byte 110 111=item SDEF IMAGE [ a0 = 1.3, s = 0.7] 112 113Applies SDEF algorithm ( second derivative operator for symmetric exponential filter) to IMAGE. 114 115Supported types: Byte 116 117=item deriche IMAGE [ alpha ] 118 119Applies Deriche edge detector. 120 121Supported types: Byte 122 123=item filter3x3 IMAGE [ matrix, expandEdges = 0, edgecolor = 0, conversionType = conversionScaleAbs, rawOutput = 0, divisor = 1 ] 124 125Applies convolution with a custom 3x3 kernel, passed in C<matrix>. 126 127Supported types: Byte 128 129Parameters: 130 131=over 132 133=item matrix ARRAY 134 135Array of 9 integers, a 3x3 kernel, to be convoluted with IMAGE. Indexes are: 136 137 |0 1 2| 138 |3 4 5| 139 |6 7 8| 140 141=item expandEdges BOOLEAN 142 143If false, the edge pixels ( borders ) not used in the convolution as center 144pixels. If true, the edge pixels used, and in this case C<edgecolor> value 145is used to substitute the pixels outside the image. 146 147=item edgecolor INTEGER 148 149Integer value, used for substitution of pixel values outside IMAGE, when 150C<expandEdges> parameter is set to 1. 151 152=item divisor INTEGER 153 154The resulting pixel value is divided to C<divisor> value after the kernel convolution is applied. 155 156=item conversionType 157 158See L<combine> 159 160=item rawOutput 161 162See L<combine> 163 164=back 165 166=item median IMAGE [ w = 3, h = 3 ] 167 168Performs adaptive thresholding with median filter with window dimensions C<w> and C<h>. 169 170=item unionFind IMAGE [ method, threshold ] 171 172Applies a union find algorithm selected by C<method>. The only implemented 173method is average-based region grow ( 'ave' string constant ). Its only 174parameter is C<threshold>, integer value of the balance merger function. 175 176Supported types: Byte 177 178=item hysteresis IMAGE, thresold => [ thr0, thr1], neighborhood => 4 or 8 179 180Perform binary hysteresis thresholding of Byte image with two thresholds, 181thr0 and thr1. A pixel is set to 1, if its value is larger than thr1 or 182if it is larger than thr0 and the pixel is adjacent to already marked pixels. 183 184Default value of neighborhood is 8. 185 186Supported types: Byte 187 188=item gaussian SIZE, SIGMA 189 190Generates a square image of the given SIZe and populates with with gaussian 191function with given SIGMA. 192 193=item laplacian SIZE, SIGMA 194 195Generates a square image of the given SIZe and populates with with inverse 196gaussian function with given SIGMA. 197 198=item gradients IMAGE 199 200This function computes a two-dimensional gradient (magnitude and direction) of 201an image, using two convolution kernels. The magnitude is computed as the 202vector magnitude of the output of the two kernels, and the direction is 203computed as the angle between the two orthogonal gradient vectors. 204 205The convolution kernels are (currently limited to) 3x3 masks for calculating 206separate vertical and horizontal derivatives. 207 208(Copyright (c) 1988 by the University of Arizona Digital Image Analysis Lab). 209 210=item canny IMAGE [ size = 3, sigma = 2, ridge = 0 ] 211 212First part of the Canny edge detector (without ridge strength 213selection). The ridge strength must be supplied by the user. 214 215=item nms IMAGE [ set = 255, clear = 0 ] 216 217Applies non-maximal suppression to the image, and replaces all 218non-maximal pixels with the C<clear> color, and maximal with C<set> color. 219 220=item scale IMAGE [ size = 3, sigma_square = 4 ] 221 222Convolves a given image with a gaussian, where the latter is 223calculated with the given size and square root of sigma_square. 224 225=item ridge IMAGE [ anorm = false, mul = 1, scale = 2, size = 3 ] 226 227First part of the Lindeberg edge detector (without scale selection). The scale 228must be supplied by the user. C<size> is used in generation of the gaussian 229kernel. C<mul> is the custom multiply factor to the calclated ridge strength, 230the maximum absolute value to the principal curvatures. C<anorm> selects 231whether the Laplacian blob response should be included ( C<false> ) ), or 232suppressed ( C<true> ). 233 234=item convolution IMAGE, KERNEL 235 236Convolves IMAGE with the given KERNEL. 237 238=item zerocross IMAGE, cmp = 0 239 240Creates a map from IMAGE where white pixels are assigned to spots 241where image crosses the zero plane. The zero level is 0 by default, 242but can be changed by setting the C<cmp> argument. 243 244=back 245 246=cut 247