User:Vismantas

=Edge Relaxation=

Introduction
Edge Relaxation is a topic in computer vision  which is discussed in CVonline and in the book Computer Vision by Dana Ballard and Christopher Brown as well as in a few other resources.

Theory
Edge relaxation is a post-processing step for an edge detection algorithm. Usually the output of an edge detection algorithm is quite noisy (resulting in gaps and cracks in edges, as well as artificial edges) and edge relaxation alleviates some effects of this noise. It achieves this by iteratively considering each edge and increasing or decreasing its confidence value based on the neighbouring edges. For example it is natural to think that a weak horizontal edge between two strong horizontal edges should also be strong. The iterations of the algorithm are finished when the confidence values of all edges converge.

The algorithm described here works on "crack" edges. Crack edge is a boundary between two pixels. Each pixel has four "crack" edges associated with it. All the edges have a direction which is a multiple of $$\pi/2$$. The magnitude of the edge is calculated as $$|f(x) - f(y)|$$, where x and y are the coordinates of the two pixels and function f gives the intensity value of the pixel. Each edge therefore has two endpoints and three neighbours at each one of the endpoints. Based on the amount of neighbors at the endpoints, every edge can be assigned a tuple of two numbers corresponding to the number of neighbour edges at each point. This tuple determines the type of the edge.

The main idea of the algorithm is to recognise certain patterns of edges (edge types) and modify the confidence of the edge according to the type.



Algorithm
Edge relaxation is an iterative algorithm. In each iteration the confidence of the edges is changed, till all the edge confidence values converge to either 0 (edge termination) or 1 (forming of border). The initial confidences of the edge can be calculated by normalising the magnitude of the edge with respect to the global maximum magnitude of an edge in the image, or with respect to some local maximum magnitude of an edge calculated in some large neighbourhood of the edge.

Following is an overall structure of the edge relaxation algorithm :


 * 1) Initialize all edge confidences $$c_1(e)$$ $$\forall e \in Edges $$
 * 2) Set k = 1
 * 3) For each $$ e \in Edges $$ determine the type of the edge.
 * 4) For each $$ e \in Edges $$ update the confidence $$ c_{k+1}(e) $$ based on the previous confidence $$ c_{k}(e) $$ value and the type of the edge.
 * 5) Stop if all the edge confidence values $$ c_k(e) $$ have converged to either 0 or 1. Repeat steps 3 and 4 otherwise.

The two most important steps are step 3, computing the edge type, and step 4, modifying edge confidence value based on its type.

Determining edge type
To determine the edge type, first of all the types of each of the vertex of the edge are determined. They are determined based on the strength of the edges that are emanating from the vertex.

$$ \begin{array}{lcl} v_{type} & = & \operatorname*{arg\,max}_k(type(k)) \text{ where } k = 0, 1, 2, 3 \\ type(0) & = & (m - a)(m - b)(m - c) \\ type(1) & = & a(m - b)(m - c) \\ type(2) & = & ab(m - c) \\ type(3) & = & abc \\ m & = & \max(a, b, c, q) \text{ where q is a small quantity to ensure type(0) for weak vertices.} \end{array} $$

For example, choosing q=0.1, a vertex (a,b,c)=(0.5, 0.05, 0.05) is a type 1 vertex, while a vertex (0.3, 0.2, 0.2) is a type 3 vertex. Parameter q ensures, that weak verteices (e.g. (a, b, c) = (0.001, 0.001, 0.001)) are assigned type 0.

Similar results alternatively can be obtained by simply counting the number of edges with confidence value above some threshold emanating from the vertex.

Edge type is found by simply concatenating the vertex types into a tuple.

Following is a table with a list of the possible edge types and corresponding changes to the confidence value :

Edge confidence is then updated based on the following formulas :

$$ \begin{array}{llcl} \text{Confidence increase:} & c_{k+1}(e) & = & min(1, c_k(e) + \delta) \\ \text{Confidence decrease:} & c_{k+1}(e) & = & max(1, c_k(e) - \delta) \\ \text{Leave confidence as is:} & c_{k+1}(e) & = & c_k(e) \end{array} $$

Where $$\delta$$ is a constant. Suggested value for $$\delta$$ is between 0.1 and 0.3.

Practical issues
Algorithm, as described above, rapidly improves the initial confidence values of the edges in a small number of iterations. However after a large number of iterations the algorithm often slowly drifts, giving results which are worse than expected. This strange behaviour is due to the fact, that the algorithm tries to find a global maximum of the edge consistency criterion, which may not give locally optimal results.

A solution to this problem is to introduce upper and lower confidence value thresholds. After reaching on of these thresholds, the confidence of the edge would be set to 0 or 1 relative to which threshold was reached.

$$ \begin{array}{lcl} \text{If } c_{k+1}(e) & > & T_{upper} \text{ set } c_{k+1}(e) = 1 \\ \text{If } c_{k+1}(e) & < & T_{lower} \text{ set } c_{k+1}(e) = 0 \end{array} $$

Where $$T_{upper}$$ and $$T_{lower}$$ are upper and lower edge confidence thresholds, that control the convergence speed of the edge relaxation.

As each edge confidence value in the new iteration only depends on its and its neighbours past confidence values, the algorithm can be easily be implemented in a parallel fashion.

Examples
Following is an example of edge relaxation applied to an edge image (It should be noted that the edge strengths have been thresholded in both images at 0.25 for display purposes only):

It can be seen that edge relaxation fills in the gaps and cracks in the already existing edges after only 5 iterations.

Applications
Edge relaxation can be applied as a post-processing step for an edge operator. Due to the noise in the images, usual edge operators return edges that have gaps and cracks, also some arbitrary edges resulting from the noise. As have been shown, the edge relaxation algorithm can successfully deal with such issues and improve the outcome of the edge operators.