Why Edge Detection? How can an algorithm extract relevant information from an image that is enables the algorithm to recognize objects? The most important information for the interpretation of an image (for both technical and biological systems) is the contour of objects. Contours are indicated by abrupt changes in brightness. We can use edge detection filters to extract contour information from an image. Types of Edges One-dimensional profiles of different edge types Types of Edges One-dimensional profile of actual edges Edge Detection First we need some definitions: An edge point is a point in an image with coordinates [i, j] at the location of a significant local intensity change. An edge fragment corresponds to the i and j coordinates of an edge and the edge orientation, which may be the gradient angle. An edge detector is an algorithm that produces a set of edges (edge points or edge fragments) from an image. 3 4 Edge Detection A contour is a list of edges or the mathematical curve that models the list of edges. Edge linking is the process of forming an ordered list of edges from an unordered list. By convention, edges are ordered by traversal in a clockwise direction. Edge following is the process of searching the (filtered) image to determine contours. Gradient In the one-dimensional case, a step edge corresponds to a local peak in the first derivative of the intensity function. In the two-dimensional case, we analyze the gradient instead of the first derivative. Just like the first derivative, the gradient measures the change in a function. For two-dimensional functions it is defined as 5 6
Gradient In order to compute G i and G j in an image F at position [i, j], we need to consider the discrete case and get: G i = F[i+, j] F[i, j] G j = F[i, j+] F[i, j] This can be done with convolution filters: G i = G j = - - To be precise in the assignment of gradients to pixels and to reduce noise, we usually apply 3 3 filters instead (next slide). 7 Sobel filters are the most common variant of edge detection filters. Two small convolution filters are used successively: - - S i - - - - S j 8 Sobel filters yield two interesting pieces of information: The magnitude of the gradient (local change in brightness): Gradient vs. Edge Orientation Note: Edge and gradient orientation are perpendicular to each other: The angle of the gradient (tells us about the orientation of an edge): 9 Here, the gradient orientation is horizontal (pointing to the right) and the edge orientation is vertical. and Thresholding Calculating the magnitude of the brightness gradient with a Sobel filter. Left: original image; right: filtered image.
The Hough transform is a very general technique for feature detection. In the present context, we will use it for the detection of straight lines and circles as contour descriptors in edge point arrays. We could use other variants of the Hough transform to detect circular and other shapes. We could even use it outside of computer vision, for example in data mining applications. So understanding the Hough transform may benefit you in many situations. The Hough transform is a voting mechanism. In general, each point in the input space votes for several combinations of parameters in the output space. Those combinations of parameters that receive the most votes are declared the winners. We will use the Hough transform to fit a straight line to edge position data. To keep the description simple and consistent, let us assume that the input image is continuous and described by an x-y coordinate system. 3 4 A straight line can be described by the equation: y = mx + c The variables x and y are the parameters of our input space, and m and c are the parameters of the output space. For a given value (x, y) indicating the position of an edge in the input, we can determine the possible values of m and c by rewriting the above equation: c = -xm + y You see that this represents a straight line in m-c space, which is our. 5 Example: Each of the three points A, B, and C on a straight line in input space are transformed into straight lines in. y A B C x input space The parameters of their crossing point (which would be the winners) are the parameters of the straight line in input space. c B C A winner parameters m 6 Algorithm:. Quantize input and s appropriately.. Assume that each cell in the parameter (output) space is an accumulator (counter). Initialize all cells to zero. 3. For each point (x, y) in the image (input) space, increment by one each of the accumulators that satisfy the equation. 4. Maxima in the accumulator array correspond to the parameters of model instances. The Hough transform does not require preprocessing of edge information such as ordering, noise removal, or filling of gaps. It simply provides an estimate of how to best fit a straight line (or other curve model) to the available edge data. If there are multiple straight lines in the image, the Hough transform will result in multiple peaks. You can search for these peaks to find the parameters for all the corresponding straight lines. 7 8 3
Improved Here is some practical advice for doing the Hough transform. The m-c space described on the previous slides is simple but not very practical. It cannot represent vertical lines, and the closer the orientation of a line gets to being vertical, the greater is the change in m required to turn the line significantly. We are going to discuss an alternative that requires a bit more computation but avoids the problems of the m-c space. Improved As we said before, it is problematic to use m (slope) and c (intercept) as an. Instead, it is a good idea to use the orientation and length d of the normal of a straight line to describe it. The normal n of a straight line l is perpendicular to l and connects l with the origin of the coordinate system. The range of is from to 36, and the range of d is from to the length of the image diagonal. Note that we can skip the interval from 8 to 7, because it would require a negative d. Let us assume that the image is 45 45 units large. 9 Row i 45 d Improved Column j 45 line to be described input space 636 The parameters and d form the for our Hough transform. d representation of same line in 36 Improved For any edge point (i, j ) indicated by our Sobel edge detector, we have to find all parameters and d for those straight lines that pass through (i, j ). We will then increase the counters in our output space located at every (, d) by the edge strength, i.e., the magnitude provided by the Sobel detector. This way we will find out which parameters (, d) are most likely to indicate the clearest lines in the image. But first of all, we have to discuss how to find all the parameters (, d) for a given point (i, j ). Improved By varying from to 36 we can find all lines crossing (i, j ): Row i 3 d 3 d d Column j (i, j ) 45 But how can we compute parameter d for each value of? Idea: Rotate (i, j ) and the normal around origin by - so that the normal lands on i-axis. Then the i-coordinate of the rotated point is the value of d. Improved And how do we rotate a point in two-dimensional space? The simplest way is to multiply the point vector with a rotation matrix. We compute the rotated point (i R, j R ) as obtained by rotation of point (i, j ) around the point (, ) by the angle as follows: 45 3 4 4
Improved We are only interested in the i-coordinate: i R = i cos -j sin In our case, we want to rotate by the angle - : i R = i cos(- ) - j sin(- ) i R = i cos + j sin Now we can compute parameter d as a function of i, j, and : d(i, j ; ) = i cos + j sin By varying we are now able to determine all parameters (, d) for a given point (i, j ) and increase the counters in accordingly. 5 5