CS 223B Project: Color Edge Detection Implementation

Kate Starbird / John Owens


Implementation

The Canny operator "detects edges at the zero-crossings of the second directional derivative of the smoothed image in the direction of the gradient where the gradient magnitude is above some threshold". [Nalwa, p.90]

The implementation of imgCanny in the img library sets the gradient magnitude equal to the square root of the sum of the squares of the gradients in each of the x and y directions.

Our implementation of imgCED calculates the 2D vector

sqrt(v) * e

where e is the direction of maximum change at any given point, and v is the square of the change in the magnitude of (r,g,b) in that direction. imgCED is similar in function to imgCanny, except it substitutes this vector for the gradient.

The 2d vector described by e1, e2 and v plays the role of the gradient in the Canny edge detector.


imgCED.c

Looping through each pixel, the derivative of intensity with respect to x and y for each of (r, g, b) is calculated. Then the 2x2 matrix Q is calculated by the matrix multiplication of the Jacobian, J, and its transposition, J'. The values of Q are then sent to the function eigen along with pointers to three floats. Resulting floats e1 and e2 contain the eigenvector of Q ((x, y) => (e1, e2)). Float v contains the eigenvalue of Q. The resulting values e1, e2 and v are placed in three separate float images. Since Q represented the squares of the directional derivatives, the square root of v is placed in the v image.

We now have a series of eigenvectors v for all pixels that reflect the magnitude of color intensity change at each pixel. We next pick only the pixels with a maximum local intensity change in the directions of their associated eigenvectors. This removes edges which are multiple pixels wide. This is accomplished by only placing the pixel eigenvalue v into the output image if the pixel eigenvalues on either side of v in the direction of v's associated eigenvector are both less than v. Otherwise, a zero is placed in the output image at that pixel.

eigen.c

The function eigen takes the matrix Q, [[q1 q2][q3 q4]] and pointers to three floats, e1, e2, and v. The eigenvector with the highest eigenvalue goes in [[e1][e2]]. The eigenvalue goes in v.


Return to project overview.