Edge Detection and Object Detection Algorithms
Edge Detection and Object Detection Algorithms
The gradient method detects the edges by looking for the maximum and
minimum in the first derivative of the image. Thus, consider the two dimensional
function f (x , y ) to represent the input image then image gradient is given by the
following formula [1]:
[ ]
∂ f (x, y)
[]
∇ f =G[f ( x , y)]=
fx
fy
=
∂x
∂ f (x, y)
∂y
(1)
The magnitude of the gradient computed by Equation (2) gives edge strength
and the gradient direction is always perpendicular to the direction of the edge.
Robert, Sobel, and Prewitt operators are classified as standard first order derivative
operators which are easy to operate but highly sensitive to noise [1].
Robert Operator
The input image is convolved with the default kernels of operator and
gradient magnitude and directions are computed. It uses the following 2 ×2 two
kernels [10]:
G x=
[ +10 −10 ] and G =[−10 +10 ]
y (4)
The plus factor of this operator is its simplicity but having small kernel it is
highly sensitive to noise and not compatible with today's technology [10].
Sobel Operator
It convolves the input image with kernel and computes the gradient
magnitude and direction. It uses the following 3 ×3 two kernels:
[ ] [ ]
−1 0 +1 +1 +1 +1
G x = −1 0 +1 and G y = 0 0 0 (5)
−1 0 +1 −1 −1 −1
Prewitt Operator
Prewitt edge operator gives better performance than that of Sobel operator.
The function of Prewitt edge detector is almost the same as Sobel detector but have
different kernels:
[ ] [ ]
−1 0 +1 +1 +1 +1
G x = −1 0 +1 and G y = 0 0 0 (6)
−1 0 +1 −1 −1 −1
2 2
2 ∂ ∂
∇ f ( x , y)= 2
f (x , y )+ 2 f (x , y ) (7)
∂x ∂y
Laplacian
The Laplacian of Gaussian (LoG) follows the following four steps [12]:
( )
2 2
x +y
−
1 2 σ2
(13)
G(x , y)= e
√2 π σ 2
2. Enhance the edges using Laplacian operator which given by this
equation [12]:
[ ]
2 2
2 2 −x + y
−1 x +y 2
log (x , y )= 4 1− 2
e 2σ
(14)
πσ 2σ
Greater the value of σ , broader the Gaussian filter, more is the smoothing.
Too much smoothing may make the detection of edges difficult; also called the
Maxican Hat operator.
Difference of Gaussian
e
−
( x 2+ y2
2 π σ1
2
) e
( −
x2 + y 2
2 πσ2
2
)
DoG (x , y )= − (15)
2 2
2π σ 1 2π σ 2
LoG requires large computation time for a large edge detector mask. Second
Order Derivative Methods Properties. The following are the three most important
properties of the second order derivatives:
1. Second order derivative methods especially Laplacian, are very sensitive to
noise.
The Canny edge detection algorithm is known to many as the optimal edge
detector. Canny's intentions were to enhance the many edge detectors already out
at the time he started his work. He was very successful in achieving his goal and
his ideas and methods can be found [2]. The first and most obvious is low error
rate. It is important that edges occurring in images should not be missed and that
there be no responses to non-edges. The second criterion is that the edge points be
well localized. In other words, the distance between the edge pixels as found by the
detector and the actual edge is to be at a minimum. A third criterion is to have only
one response to a single edge. This was implemented because the first two were
not substantial enough to completely eliminate the possibility of multiple responses
to an edge.
Based on these criteria, the Canny edge detector first smoothies the image to
eliminate the noise. It then finds the image gradient to highlight regions with high
spatial derivatives. The algorithm then tracks along these regions and suppresses
any pixel that is not at the maximum (non-maximum suppression). The gradient
array is now further reduced by hysteresis. Hysteresis is used to track along the
remaining pixels that have not been suppressed. Hysteresis uses two thresholds and
if the magnitude is below the first threshold T 1, it is set to zero (made a non-edge).
If the magnitude is above the high threshold T 2, it is made an edge. And if the
magnitude is between the two thresholds, then it is set to zero unless there is a path
from this pixel to a pixel with a gradient above the second threshold T 2. In order to
implement the canny edge detector algorithm, a series of steps must be followed
[13].
Step 1: Smooth the image with a two dimensional Gaussian filters.
Step 3: The direction of the edge is computed using the gradient in the x and
y directions.
Step 4: relate the edge direction to a direction that can be traced in an image.
Step 6: Hysteresis.
Each edge detection method has its advantages and disadvantages. Table 1
summarize the main advantages and disadvantages of each method [12].
Edge Detection Using Wavelets
(( ) ( ) )
x−μ x 2 y− μy 2
1
+
1 2 σx σy
(16)
θ(x , y)= e
2 π σxσ y
( )
∂
( f ∗θ s ) (x , y )
( )
1
ws f (x , y ) ∂x
2
=s =s ∇ ( f ∗θ s ) ( x , y ) (21)
W s f (x , y) ∂
∂y
( f ∗θs ) (x , y)
The Smoothing
Smooth the image and detect the sharp variation points from their first order
derivative. The smoothing function is any function whose integral is equal to 1 and
that converges to 0 at infinity. One can choose smoothing function equal to a
Gaussian.
(( ) ( ) )
x− μx 2 y− μy 2
−1
+
1 2 σx σy
(22)
θ(x , y)= e
2 π σxσ y
In order to compute the local maxima of the modulus of the image in DWT
need to find: 1 -the modulus and 2- the angle of the DWT at each scale. The
modulus maxima are then defined as the points of the modulus images that are
larger than the two neighbors whose positions are in the direction indicated by the
angle value at the corresponding location. Let's see how to get the modulus of an
image:
√ 2 2
M s f (x , y )= |W s f ( x , y)| +|W s f (x , y)|
1 2
(23)
Then get the angle of the DWT. There are only four possible directions
when describing the surrounding pixels: 0 degree (in the horizontal direction), 45
degree (along the positive diagonal), 90 degree (in the vertical direction), or 135
degree (along the negative diagonal). From the modulus image and the angular
DWT can find the local modulus maxima.
Thresholding
Although the maxima of the modulus of the discrete wavelet transform are a
good approximation of the edges in an image, even in the absence of noise often
there are many false edges as can be seen. Therefore a criterion such as
thresholding must be determined to separate the "true" edges from the "false"
edges.
3. Use an averaging mask over the image and resize the image. To limit
computation time, resize the image to have 256 rows and columns that are
proportion to it i.e. the original aspect ratio is maintained as shown in
Figure 7.
4. A histogram of the image is generated. Thus, the result is of the form
[intensity level, number of pixels with that intensity level] as shown in
Figure 8.
5. From the histogram data, created a set of values from which the local peaks
are counted 58 elements.
6. From the above set, created a set where the peaks that are within 1 % of the
maximum value (of the number of pixels corresponding to the same
intensity level) are counted and others are discarded 57 elements. This factor
has been statistically obtained from assessing many images [17].
7. From the set created in the previous step, remove the peaks that correspond
to intensities that are within 20 levels of each other 7 elements. The number
20 is again found effective after experiments by [17]. The number of peaks
which are thresholds that can consider from the image. They represent the
significant peaks in the histograms shown in Figure 9.
8. Using the threshold values above, find out the optimal threshold using Otsu's
method; Thresh = [53 74 98 128162190 218].
9. Based in the thresholds obtained from Otsu's method, segment the resized
image as shown in Figure 10.
Simulation Results
where, false edges are the non-edge pixels identified as edges, I A is the
detected edges, I I is the ideal edges, d is the distance between actual and ideal
edges and ∝ is the penalty factor for displaced edges. (PR, PSNR, FoM), higher the
value of these parameters better the result is. (MSC, FAC), lower the value of these
parameters better the result is. Table 2 summarizes the performance measures of
standard edge detection methods mentioned in this paper with and without
preprocessing approach.
(c) (d)
(e) (f)
(g) (h)
(i) (j)
(k) (l)
Figure 11. Comparison between various edge detection models (a) Original image;
(b) Ground truth; (c) Robert; (d) Reviewed by Robert; (e) Prewitt; (f) Reviewed by
Prewitt; (g) LoG; (h) Reviewed by LoG; (i) Canny; (j) Reviewed by Canny; (k)
Wavelet; (l) Reviewed by wavelet.
Illumination Changes
Viewpoint Variation
Changes in the viewpoint or camera angle can alter the object's appearance,
causing the detection algorithm to fail in recognizing the object or produce
inaccurate bounding boxes [27]. Several methods have been considired to tackle
this issue, such as viewpoint invariant features and multi- view object detectors
[27].
Occlusion
Objects in the scene may be partially or entirely occluded by other objects,
making it challenging for the detection algorithm to identify and localize them
correctly [28]. To address occlusion, some methods employ part-based models [29]
or leverage context information from surrounding regions.
Datasets
Pascal VOC
The PASCAL VOC (Visual Object Classes) dataset is one of the oldest and
most popular datasets for object detection. It contains 17,125 images with 20
object classes, such as person, car, and dog. The dataset provides bounding box
annotations for each object in the image. PASCAL VOC has been used as a
benchmark dataset for several years, and many state-of-the-art object detection
techniques have been evaluated on this dataset.
ImageNet
The ImageNet dataset is a massive dataset that contains 1.2 million images
with 1,000 object classes. Unlike PASCAL VOC, ImageNet does not provide
annotations for object detection. However, many researchers have used this dataset
to pre-train their models on a large amount of data before fine-tuning them on
smaller object detection datasets.
COCO
Open Images
The Open Images dataset is another large-scale dataset that contains 1.7
million images with 600 object classes. It provides both bounding box and
segmentation mask annotations and has been used as a benchmark for object
detection algorithms that require large amounts of training data.
Number of
Dataset Name Number of Classes Annotation Type
Images
Two-stage detectors
R-CNN
fixed size and fed through a pre-trained CNN, such as Alex Net or VGG, to
extract a feature vector for that region.
2. Object Classification and Refinement: The feature vector for each region
proposal is then fed into a set of fully connected layers that perform object
classification and bounding box regression. The classification layer outputs
the probability of each region proposal containing a particular object class,
while the regression layer outputs the refined bounding box coordinates for
that object class.
Fast R-CNN
Single-stage detectors
YOLO
YOLO is another one-stage object detection model that predicts object class
scores and bounding box offsets directly from the entire image. YOLO divides the
image into a grid of cells and predicts the class and bounding box for each cell.
YOLO uses a single neural network to make predictions and is known for its speed
and real-time performance.
The Single Shot MultiBox Detector (SSD) extends the concept of YOLO by
predicting bounding boxes and class probabilities at multiple scales, which
improves the detection of objects with varying sizes. SSD uses a feature extractor
to generate convolutional feature maps and applies a set of convolutional filters to
predict class scores and offsets for each default box. SSD is known for its speed
and efficiency and has been used in real-time object detection applications.
Retina Net
Retina Net introduces the Focal Loss, which addresses the issue of class
imbalance by down weighting the contribution of easy examples and focusing on
hard examples during training. This results in improved detection performance,
particularly for small objects. Retina Net uses a novel focal loss function that
assigns higher weights to hard examples and reduces the effect of easy examples
during training. Retina Net also uses a Feature Pyramid Network (FPN) to handle
objects at different scales and has achieved state-of-the-art performance on several
object detection benchmarks.
Figure 17. RetineNet – Object Detection Algorithm
Faster R-CNN
Long Medium High 39.3
[35]
Comparative Analysis
SSD 72.1 19
RetinaNet 74.8 12