In order to show the need for filtering, we here present the impact of several filters on a Marr-Hildreth edge detection algorithm.
1) No Filtering
The pictures below illustrate the fact that edge detection is very sensitive to noise. As noise creates local variations in the image intensities, it can provoke an edge detection algorithm to generate irrelevant edges.
2) Gaussian Blurring
Using a gaussian filter is a well-known way of reducing the noise. Besides this effect which is a goal we attempt to reach, Gaussian blurring doesn't preserve edges. This is due to the fact that convolution with a gaussian kernel in the space domain corresponds to filtering with a low-pass gaussian filter in the frequency domain. Hence, this process removes all high-frequency content in the picture and smooths all initially sharp transitions such as edges.
Standard deviation = 3
Standard deviation = 10
3) Median Filtering
Median filtering is a much better estimate than the average since it reduces the influence of outliers. However, median filtering tends to round corners. This means that the edges will be pushed in or out depending on the inflexion of the curve. Hence median filtering does not fully preserve the original shape of the edges.
Mask Size = 5
Mask Size = 10
4) Anisotropic Diffusion
Anisotropic diffusion is based on the heat-equation PDE, to which a conductance term has been incorporated. If the conductance term is picked to be high, one can see that this generates a result close to blurring, since values in between pixels are flowing without tight enough contraints. On the other hand, choosing a small conductance restricts the flowing to regions which are homogeneous in some respect. The number of iterations corresponds to how deep the user wants to burry the noise. However, a too high number of iterations creates a degenarated picture.
Conductance = 5.0, Iterations = 10
Conductance = 1.1, Iterations = 10
Conductance = 1.1, Iterations = 100
II) Edge Detectors
Here, we use the anisotropic filtering (Conductance = 1.1, Iterations = 10) on the input to different edge detectors. We compare the Marr-Hildreth with the Canny edge detector. When looking at the results, it seems obvious that the accuracy of the Marr-Hildreth filter is much lower than the one of the Canny detector. In addition to that, the Canny detector algorithm relies on a threshold that the user can set to disregard weak edges.
III) Line Features
Below are displayed all the necessary steps to feature detection. The initial picture is first filtered using anisotropic diffusion. A Canny edge detector is then applied which will provide an input to the Hough transform. The Hough transform accumulates all the possible lines going through the points in the detected edges into a polar coordinate system. The wave functions are drawn in the accumulator in a bilinear antialiasing fashion in order to reduce the errors introduced by the discretization of the space. The accumulator space has been chosen to be represented in polar coordinates in order to avoid potentially unrestricted range of the values to be part of that domain. We know in our case that theta ranges in [0, PI[ and that rho is in [-rhoMax, rhoMax] where rhoMax is determined by the length of the diagonal in the initial picture. The resolution of the representation of the accumulator space remains to be defined. We set it to be 1024^2 for all our examples. Pictures of the accumulator space are shown here on a log scale for ease of visualization.
In order to eliminate the potential local maxima that would result from noise in the accumulator space, the result of the Hough transform is blurred using a gaussian filter with a small standard deviation (= 3). This step requires implementing a gaussian filtering that deals with the periodic boundary condition along the theta axis of the accumulator space. This must be done carefully since the periodicity flips the sign of the rho coordinate, and hence can be seen as an axial reflexion along the theta axis.
Following this step, all the local maxima in the accumulator space are computed in order to determine the sets of points more likely to belong to a line in the original picture. Close local maxima defining lines with correlated equations are merged to gather the main lines together. This also needs to be done accross the periodic boundary while accounting for changes in the sign of rho as the boundary is crossed. Pictures representing the local maxima are rescaled to fit in the browser's page, and are consequently difficult to analyse. Please look at the picture itself directly from the corresponding folder for more accurate visualization.
The final step consists in thresholding the maxima values and drawing the associated lines in the initial picture. Those are also antialiased for nicer visualization.
The threshold value to be used can alternatively be obtained from a function which sorts all the local maxima by descending weight and then returns the threshold to be used in order to only conserve the n most prominent lines where n is given as a parameter.