• Aucun résultat trouvé

Edge Detection

Dans le document Advances in Pattern Recognition (Page 162-173)

Edge detection is an image processing activity aimed at finding the boundaries of the elements represented in images. In fact, this is often a preliminary step to the identification and recognition of interesting image details, such as objects or peculiar patterns. The possible approaches can be divided into two categories, each of which in turn includes several techniques:

Fixed methods detect shapes in the image by comparison to a set of stored tem-plates, which significantly limits the number of shapes that can be actually recog-nized. Indeed, being infeasible to store all possible shape templates, it may happen that the shape of interest is not present in the database. These include, among oth-ers, Pixel luminance (e.g., Image thresholding); Template matching; the Hough Transform.

Flexible methods repeatedly modify a tentative shape until it overlaps the target shape that is present in the image. They can be distinguished according to the function exploited to determine the degree of correspondence between the data in the image and the tentative shape, and also according to the kind of tentative shape exploited. Examples of this category are Deformable Templates and Active Contour Models.

A naive Image Thresholding technique consists in identifying the set of pixels that delimit an object by enhancing the changes in luminance through proper fil-ters (such as those introduced in previous sections), then binarizing the image (the previous step should have improved the starting situation for the threshold determi-nation). Each connected component obtained in this way can be considered an object shape, possibly to be refined (e.g., using erosion or contour following) and matched against available templates. Figure4.3shows an application of this procedure.

The Deformable Template technique consists in modifying a reference model (the template) made up of one or more shapes, in order to match them as much as possible with the shape to be recognized in the image at hand. One of the earlier ap-proaches aimed at extracting facial features for identification purposes (by matching eyes to circles enclosed in opposite parabolæ) [13]. Each point(x, y)of the template shapes ‘has’ (i.e., is associated to) an energyE(x, y), and the energy of a shape is given by the sum of the energies of all its points. Modifications to the template are made by changing the shapes’ position and orientation, but keeping unvaried the spatial relationship among them. Such changes take place by searching for the shape-defining parameter values that maximize their energy. Energy is normalized for each shape (e.g., based on its perimeter) to avoid maximization tending towards the shape having the largest size. If available, more information about the shape to

Fig. 4.3 Naive technique for identifying objects in a raster image. From left to right: original image, gray level representation, Sobel horizontal and vertical components, merge of such compo-nents with associated, Otsu thresholding, connected component separation

be extracted can be exploited by the procedure. In order to maximizeE, however, many parameter values come into play. Since iterating over all combinations of pos-sible values for each parameter is infeapos-sible, optimization techniques are exploited, or fewer parameters are taken into account,3 as in the snakes approach presented afterward.

Canny A state-of-the-art algorithm for edge detection, although improvements thereof are available, is considered the one proposed by Canny [2]. It can find step-and ramp-shaped edges (even in images affected by white noise), step-and turns out to be optimal with respect to several parameters: precision and recall of the retrieved edges (detection), tolerance in the retrieved edge compared to the actual one (lo-calization), and avoidance of multiple outcomes for a single edge (one response:

a single edge should be returned for each point of the actual edge). The first and last criteria are strictly related, in that worst edges are eliminated from competing candidates.

The algorithm applies repeatedly the following basic steps:

1. ConvolveI with a Gaussian of standard deviationσ,G(x, y)=e

x2+y2 2 ; 2. Estimate for each pixel in the image the local directiondnormal to the edge;

3. Find the location of the edges using non-maximal suppression;

4. Compute the magnitude of the edge;

5. Threshold edges in the image to eliminate spurious responses,

3A way to obtain a ‘useful’ smaller set of parameters is using Principal Component Analysis (PCA), a mathematical procedure that transforms a number of possibly correlated variables into a smaller number of uncorrelated variables (the principal components), each of which accounts for a portion of variability in the data (and can be ranked according to how much variability it catches).

for ascending values of the scaleσ, and the final information about edges at multiple scale is aggregated using the ‘feature synthesis’ approach. However, since it is quite time-consuming, often these additional steps are omitted, if thorough robustness of the outcome is not strictly needed.

Step 1 blurs the image, using for convolution a Gaussian mask of sizen×n, where the value ofnmust be defined. Some authors suggest taking it as the smallest odd integer n≥6σ to provide ‘full’ power to the Gaussian filter (smaller filters would result in less smoothing).

Then, as to step 2, for each point(x, y) in the image, the magnitude and an-gle/direction of the gradient are, respectively,

M(x, y)= SinceMis obtained using the gradient, it contains crests around the local maxima, and thus such values must be thinned using non-maxima suppression. For this, a fi-nite number of directions to be considered must be specified. In an 8-neighborhood approach, since pairs of opposite directions both denote the same edge, just four (the horizontal, the vertical and the two diagonals) can be considered, placed at 45°

from each other. The edge direction is orthogonal to that of the gradient expressed byα(x, y). Thus, the non-maxima suppression schema might be as follows:

1. Find the directiond(among the above four) closest toα(x, y)

2. if the valueM(x, y)is smaller than at least two of its neighbors alongd (a) then setgN(x, y)=0 (suppression)

(b) else setgN(x, y)=M(x, y), wheregN(x, y)is the final image.

Lastly,gN(x, y)must be thresholded to reduce false edge points. Too low thresh-olds yield false positives, while too high ones yield false negatives (i.e., eliminate correct edges). Canny uses thresholding based on hysteresis, and hence two thresh-olds: a lower oneTLand a higher oneTH, suggesting the latter to be twice or three times as large as the former. Thus, two additional images are obtained, respectively:

gNH(x, y)= gN(x, y) ifgN(x, y)TH,

0 otherwise,

gNL(x, y)= gN(x, y) ifTLgN(x, y) < TH,

0 otherwise.

The gN(x, y) < TH condition in the definition of gNL(x, y) ensures that the two images have disjoint non-null values. Indeed, otherwise ifTL< TH, the set of non-null pixels in the former (strong edges) would be a subset of those in the latter (weak edges).

All strong edges are directly considered as edges. Obviously, they are typically affected by significant fragmentation (the higher theTH, the more empty regions).

Longer edges are obtained as follows:

1. for all edge (i.e., non-zero) pixelspingNH(x, y)

(a) Label as valid edge pixels all weak pixels ingNL(x, y)that are connected to p(e.g., by 8-connectivity)

2. Set to zero all pixels ingNL(x, y)that have not been labeled as valid edge pixels 3. Add togNH(x, y)all non-zero pixels ingNL(x, y)

In practice, there is no real need for two additional images, since everything can be done directly during non-maxima suppression.

Hough Transform The Hough Transform [6] is a parametric method to identify a shape within a distribution of points. Of course, drawing on the image all possible instances of the shape and counting the number of overlapping points for each is infeasible (although finite, due to the image being finite). Hough proposed switch-ing on the opposite perspective, and countswitch-ing for each point in the original image the possible shapes that pass through that point. The shape must be parametrically defined, which makes such a technique very suitable for regular geometrical shapes.

This is less limiting than it might seem because regular geometrical shapes indeed pervasively occur as sub-components of real-world images. The basic idea consists in searching for the shapes in the space defined by the shape parameters (parameter space).

The algorithm is based on an accumulator, a multi-dimensional array that counts how many foreground points in the image are intersected by each possible shape, and in short works as follows:

1. for all non-background points(x, y)in the imageI

(a) for all values(v1, . . . , vn)of the set ofn parameters, each sampled in the suitable range with a discrete stepi

(i) Increase the accumulator cell addressed by the coordinates(v1, . . . , vn) (b) Select as significant instances of the shape in the image the points in the

parameter space having larger accumulator values associated.

A number of issues must be dealt with in order to practically apply this algo-rithm. First of all, the selection of ‘high’ accumulator points is not trivial: taking the absolute maximum would return only a few prominent instances of the shape (and in general smaller instances are underestimated because they are made up of fewer points so that some kind of normalization would be desirable). To tackle this, a threshold is often used, or all local maxima (points in the accumulator whose neighbors are smaller) are selected. In both cases, however, the approximations ap-plied during the algorithm execution cause a shape to be actually represented by a set of neighbor points rather than by a single point in the parameter space: hence, proper techniques are needed to identify such regions, and their centroid is usually taken as the single shape representative. Another issue concerns efficiency: smaller in-crements cause more refined shape identification, but increase runtime and memory requirements for storing and filling the accumulator. In the following, the case of straight lines will be discussed in more depth, to provide an understanding of the method. Application to other shapes will be just sketched.

It is well-known that the equation of a line in theX–Y plane is y=ax+b,

wherea denotes the slope (0 for horizontal, negative for descending towards the right-hand-side, positive for ascending towards the right-hand-side, infinite for the vertical) andb is the height on theY axis forx=0. Having fixed an image point p=(x, y), all possible lines passing throughpsatisfy the equation

b= −ax+y,

where now the constants arexandyand the variablesaandb(or, equivalently,bis a function ofa). Thus, in the new planeA–B that represents the parameter space for lines, the set of all lines passing throughp is itself a line (a point in the image is represented by a line in the parameter space, and vice versa). Now, finding the segment that connects two points means finding thea andbparameters such that both instances of the above equation applied to the coordinates of the two points are satisfied. Put it another way, the intersection of two lines in the parameter space denotes (the parameters of) a line in the image that passes through the two points to which the lines in the parameter space are associated. More generally, the set of lines in the parameter space that meet each other in a given point represents all points in the image that belong to the same line: the larger the cardinality of such a set, the more significant such a line in the image. For identifying segments in the image, the accumulator can be extended to store, in addition to the number of points intersected by the lines, the segment extremes as well, that are checked and updated each time a new point is added.

Actually, the linear equation for lines is a bit odd because vertical lines, corre-sponding to infinite slope, cannot be represented. A more suitable representation is the polar one that expresses them in terms of angleθover theXaxis and radiusr:

r=xcosθ+ysinθ,

wherer is a function of θ. The angle can range in [0, π[only (the other angles will denote just the same lines, considered in the opposite direction). The maximum segment length to be considered corresponds to the image diagonal, and hence, if the representation places the origin in the center of the image, the maximum radius is just one half of it:

r=1 2

width(I )2+height(I )2=1 2

#

n2+m2.

The same principle can be applied to more complex shapes, but the number of parameters, and hence the problems of efficiency, may grow significantly. As to circles, the equation of a circle having center(xc, yc)and radiusris

r2=(xxc)2+(yyc)2,

where, having fixed a pointp=(x, y)in the image, there are three degrees of free-dom (and hence parameters, and hence dimensions of the accumulator):xc,ycandr.

For each given radiusr, the set of all circles passing through pointpin the image corresponds to a circle of radiusrin the parameter space (a symmetry with the case of lines), and hence all circles of any radius forpcorrespond to cones in the whole space. For ellipses, the matter is yet more complex, since there are five parameters (xc andyc, coordinates of the center,rM andrm, the radii, andθ, the slope of the major diameter over theXaxis), which makes memory requirements quite stringent even for large’s.

Polygonal Approximation Polygonal approximation of contours is concerned with describing complex shapes as polygons each of whose sides represents a piece of contour which is actually more complex than a straight segment, while preserving the overall ‘flavor’ of the original shape. This allows a more compact representation, and can be deemed as a feature extraction technique (e.g., for supporting compar-ison between shapes). Two strategies can be applied: a sequential one that follows the shape contour, deciding at each point if a vertex of the polygon should be placed there or not, and an iterative one where starting from a triangle the side that less fits the curve is repeatedly identified and properly split, until a termination condition is met.

A fast sequential algorithm (at partial expenses of precision) for performing such a task was proposed in [12], where each point in the shape is examined only once to decide whether it may represent a vertex of the target polygon. Differently from other techniques, each polygon side starts and ends on points actually belonging to the shape. The original shape, made up ofnpoints, can be described explicitly as a sequence of pointsp0, . . . , pn(which allows expressing non-uniformly spaced points) or by delineating its contour (e.g., using a border following technique) and representing it, for the sake of compactness, as a chaincodep0, d1, . . . , dnwhere p0 is the starting point andd1, . . . , dn are the directions that identify each of the next pointsp1, . . . , pnin the shape, withpn=p0.

The algorithm exploits a thresholdT that represents the maximum allowed area deviation per length unit of the polygon side (and hence, the larger theT, the longer the segments and the looser the approximation of the original shape), expressed in pixels:

1. Initializev1p0=(x0, y0),i←0,j ←1 2. repeat

(a) Assumevj=(0,0), by translating the coordinate system if necessary (b) Initializefi=0

(c) repeat (i) ii+1 (ii) Li=

xi2+yi2, the length of the current line segment fromvjtopi = (xi, yi)

(iii) Update the deviation accumulatorfi=fi1+fi, wherefi =xi· yiyi·xi withxi, yi the increments4

until(|fi|> T ·Li)(pi=p0)

4If each pointpiis a neighbor ofpi−1(i.e., points are equally spaced),xi, yi∈ {0,1}.

(d) jj+1 (found a new vertex in the polygon)

(e) ii−1 (the previous point was the last acceptable one)

(f) vj =pi is the next vertex in the polygon, because the longest acceptable segmentvj1vj has been found

untilpi=p0(back to the starting point)

In the end, the sequence of{vj}j=1,...,mdenotes the set of vertices of the polygon approximating the original shape, andmis the number of sides of such a polygon.

The authors report that the increment caused by extending the end of a segment starting invjfrom a pixelpi1to the next pixelpi can be expressed as

fi=Li·Di,

whereDi is the (signed) distance betweenpi1and the new segmentvjpi, which (by straightforward geometrical considerations) turns out to be the doubled area of the trianglepi1vjpi. This yields a total area deviation for a segment reaching the kth point aftervj equal tofk/2=$k

i=1fi/2=$k

i=1LiDi/2.

A weakness of the method is that very narrow peaks in the shape to be ap-proximated could be lost in the polygon, since the area deviation accumulated by skipping them in the current segment is very low. In case they are to be preserved as significant, a slight modification of the algorithm is needed. While building a segment starting invj, the farthest pointp from vj is stored (candidates can be noticed because the lengthL of the current segment decreases in the next point);

if L keeps decreasing for several points, the point pi whose distanceD from p reaches the value ofT is considered as well. Then, the next vertexvj+1is taken as pfor having a better approximation (with the disadvantage of additional calcula-tions to restart again frompand follow again the partial contour fromptopi), or aspi.

A lossless way to improve speed is to avoid computing the square root in the inner loop by testing the squared conditionfi2> T2·L2i, whereL2i can be obtained by just updating the previous value:5

L2i =Li1+2·(xixi+yiyi)+(xi)2+(yi)2.

Further, but lossy, speed-up can be obtained by approximating Li as |xi| +

|yi| ≥Li (which overestimates the value and hence yields rougher shape ap-proximations) or as max(|xi|,|yi|)Li (which underestimates the value and hence yields finer shape approximations), with the advice that the orientation of the line segments affects the closeness of such an approximation to the actual value.

The authors also suggest that, having fixed an even number k of consecutive pixels in the shape, the likelihood that a pointpi+k/2is a corner is proportional to

5Note once again that, for uniformly spaced points,xi, yi∈ {0,1} ⇒(xi)2, (yi)2∈ {0,1} as well, which clearly makes this computation trivial.

the area deviation for the line segmentpipi+j divided by the length of the current segment.

Snakes Snakes [7] are an active contour technique aimed at identifying the outline of the main object (the salient contour) represented in an image. Instead of finding separate pieces (e.g., segments) of the contour, this strategy works on a closed shape having vertices v= {v0, . . . ,vn}(where vn=v0), and progressively moves and de-forms its sides and corners according to several energy factors. Since the approach performs an energy minimization based on local optima rather than global ones, different alternative solutions are possible, and the desired one can be returned if the snake is initialized close to it by someone or by some preceding technique.

Then, it carries out the rest of the task autonomously. The model is active in that it dynamically minimizes its energy functional. It is named after the behavior of the contours while being deformed because of energy minimization, resembling a snake.

A snake can be represented parametrically as v(s)= (x(s), y(s)), where s∈ [0,1] are the points of the snake normalized into [0,1]. In a discrete refer-ence system with steph, such as an image, vi=(xi, yi)=(x(ih), y(ih)). The basic model is a controlled continuity spline influenced by image forces and external con-straints forces generated to minimize the overall energy functional of the snake, defined as

whereEint is the internal energy of the spline due to bending, used to impose a piecewise smoothness constraint;Eimgrepresents the energy related to some image feature (typically, the image brightness) for attracting the snake towards edges, lines and salient contours; andEcon gives rise to the external constraint forces in charge of placing the snake near the desired local minimum.

The internal energy

controls the behavior of the snake both as a membrane and as a thin plate, weight-ing their relative importance by means of parametersα(s)andβ(s), respectively

(settingβ(s)=0 causes a second-order discontinuity, i.e., generates an angle, ats).

The use of an iterative technique based on sparse matrix methods allows processing the whole set of points in the snake in a linear number of steps.

The total image energy is a combination of three elements (energy functionals) that attract the snake towards lines, edges and terminations in the image, respec-tively, weighted differently to obtain snakes with different behavior:

Eimg=wline·Eline+wedge·Eedge+wterm·Eterm.

The line component can just work on image intensity:Eline=I (x, y)(the sign of wlinedetermines whether the snake is attracted by light or dark contours). Another option consists in following the scale space approach, taking the snake to equilib-rium on a blurry image and then fine-tuning the details by progressively reducing the level of blur. The component in this case becomesEline= −(Gσ2I )2, where

The line component can just work on image intensity:Eline=I (x, y)(the sign of wlinedetermines whether the snake is attracted by light or dark contours). Another option consists in following the scale space approach, taking the snake to equilib-rium on a blurry image and then fine-tuning the details by progressively reducing the level of blur. The component in this case becomesEline= −(Gσ2I )2, where

Dans le document Advances in Pattern Recognition (Page 162-173)