Computational Methods
Computational Methods
B. Edge Detection
Edge detection is a well developed field on its own within image processing. Edge detection is
basically image segmentation technique, divides spatial domain, on which the image is defined,
into meaningful parts or regions. Edges characterize boundaries and are therefore a problem of
fundamental importance in image processing. Edges typically occur on the boundary between
two different regions in an image. Edge detection allows user to observe those features of an
image where there is a more or less abrupt change in gray level or texture indicating the end of
one region in the image and the beginning of another. It finds practical applications in medical
imaging, computer guided surgery diagnosis, locate object in satellite images, face recognition,
and finger print recognition ,automatic traffic controlling systems, study of anatomical structure
etc. Many edge detection techniques have been developed for extracting edges from digital
images. Gradient based classical operators like Prewitt, Sobel were initially used for edge
detection but they did not give sharp edges and were highly sensitive to noise image. But
algorithm proposed by John F. Canny in 1986 is considered as the ideal edge detection algorithm
for images that are corrupted with noise. Canny's aim was to discover the optimal edge detection
algorithm which reduces the probability of detecting false edge, and gives sharp edges.[1]-[5]
[
Di= −2 0 +2
−1 0 +1
I.2. Canny edge detector: [1]-[5]
] and
[
D j= 0 0 0
−1 −2 −1 ]
Canny edge detector is an optimal edge detection technique as provide good detection, clear
response and good localization. It is widely used in current image processing techniques with
further improvements. The Canny edge detector uses a multi-stage algorithm to detect a wide
range of edges in images. The algorithm runs in 4 separate steps:
1. Smoothing: Noise contained in image is smoothed by convolving the input image I (i, j)
with Gaussian filter G. Mathematically, the smooth resultant image is given by
F(i , j)=G∗I (i, j ) (4)
2. Finding gradients: In this step, edges are detected where the change in grayscale intensity
is maximum. Required areas are determined with the help of gradient of images. Sobel
operator is used to determine the gradient at each pixel of smoothened image. Sobel
operators in i and j directions are given as
−1 0 +1 +1 +2 +1
[
Di= −2 0 +2
−1 0 +1 ] and
[
D j= 0 0 0
−1 −2 −1 ]
These sobel masks are convolved with smoothed image and giving gradients in i and j
directions.
Gi=D i ×F (i , j) and Gi=D j ×F(i , j) (5)
Therefore edge strength or magnitude of a pixel is given by
G= G 2 +G 2
√ i j (6)
The direction of gradient is given by
G
θ=arctan j
( )
Gi
(7)
Gi and Gj are the gradients in the i-th and j-dimensions respectively
3. Non-maximum suppression:
Non maximum suppression is carried out to preserves all local maxima in the gradient
image, and deleting everything else this results in thin edges. For a pixel M (i, j):
Firstly round the gradient direction Ѳ nearest45°, then compare the gradient
magnitude of the pixels in positive and negative gradient directions i.e. If gradient
direction is east then compare with gradient of the pixels in east and west
directions say E (i, j) and W (i, j) respectively.
If the edge strength of pixel M (i, j) is largest than that of E (i, j) and W (i, j), then
preserve the value of gradient and mark M (i, j) as edge pixel, if not then suppress
or remove.
4. Double thresholding:
The output of non-maxima suppression still contains the local maxima created by noise.
Instead choosing a single threshold, for avoiding the problem of streaking two thresholds
thigh and tlow are used.
For a pixel M (i, j) having gradient magnitude G following conditions exists to detect
pixel as edge:
If G < tlow than discard the edge.
If G > thigh keep the edge.
If tlow < G < thigh and any of its neighbors in a 3 ×3 region around it have gradient
magnitudes greater than thigh, keep the edge.
If none of pixel (i, j)’s neighbors have high gradient magnitudes but at least one
falls between tlow and thigh search the 5 × 5 region to see if any of these pixels have
a magnitude greater than thigh. If so, keep the edge.
Else, discard the edge.
The k-nearest-neighbor classifier is commonly based on the Euclidean distance between a test
sample and the specified training samples. Let xi be an input sample with p features (xi1,xi2,…,xip),
n be the total number of input samples (i=1,2,…,n) and p the total number of features (j=1,2,
…,p) . The Euclidean distance between sample xi and xl (l=1, 2…, n) is defined as
d ( x i , x l )= √∑ ( x ij− xlj )2
(8)
The training phase of the algorithm consists only of storing the feature vectors and class labels of
the training samples. In the actual classification phase, the same features as before are computed
for the test sample (whose class is not known). Distances from the new vector to all stored
vectors are computed and k closest samples are selected. The new point is predicted to belong to
the most numerous class within the set.
The best choice of k depends upon the data; generally, larger values of k reduce the effect of
noise on the classification, but make boundaries between classes less distinct. A good k can be
selected by parameter optimization using, for example, cross-validation. The special case where
the class is predicted to be the class of the closest training sample (i.e. when k = 1) is called the
nearest neighbor algorithm.
The accuracy of the k-NN algorithm can be severely degraded by the presence of noisy or
irrelevant features, or if the features scales are not consistent with their relevance. A particularly
popular approach is the use of evolutionary algorithms to optimize feature scaling. Another
popular approach is to scale features by the mutual information of the training data with the
training classes. The algorithm is easy to implement, but it is computationally intensive,
especially when the size of the training set grows.
If the number of classes are more than two, then a natural extension of Fisher Linear
discriminant exists using multiple discriminant analysis. As in two-class case, the projection is
from high dimensional space to a low dimensional space and the transformation suggested still
maximizes the ratio of intra-class scatter to the inter-class scatter. But unlike the two-class case,
the maximization should be done among several competing classes. Suppose that now there are n
classes.
For the n classes, the intra-class matrix is given by
n ¿ ¿
S w =S1 + ¿⋅¿+ S n=∑ ∑ ( x−x i )( x−x i )'
i=1 x ∈ c
i
(13)
The inter-class scatter matrix is given by
n ¿ ¿ ¿ ¿
S B =∑ mi ( xi −x )( x i−x )'
i=1
(14)
¿
Where
mi is the number of training samples for each class, x i is the mean for each class
¿
1 n ¿
¿¿
x= ∑ m x
and mi(xi−x) is total mean vector given by m i=1 i i
and
d ( x , y )=1−
√∑ i ( x i− yi )
2
cosine measure
√∑ √∑ i x i2 i y2
i
. Then upon the arrival of the new instance z,
¿
arg min d ( zφ , x k φ ) ¿