A FPGA Based Implementation of Sobel Edge Detection 2017
A FPGA Based Implementation of Sobel Edge Detection 2017
PII: S0141-9331(16)30228-9
DOI: 10.1016/j.micpro.2017.10.011
Reference: MICPRO 2629
Please cite this article as: Nazma Nausheen, Ayan Seal, Pritee Khanna, Santanu Haldar, A FPGA
based Implementation of Sobel Edge Detection, Microprocessors and Microsystems (2017), doi:
10.1016/j.micpro.2017.10.011
This is a PDF file of an unedited manuscript that has been accepted for publication. As a service
to our customers we are providing this early version of the manuscript. The manuscript will undergo
copyediting, typesetting, and review of the resulting proof before it is published in its final form. Please
note that during the production process errors may be discovered which could affect the content, and
all legal disclaimers that apply to the journal pertain.
ACCEPTED MANUSCRIPT
Highlights
T
IP
CR
US
AN
M
ED
PT
CE
AC
ACCEPTED MANUSCRIPT
Noname manuscript No.
(will be inserted by the editor)
T
IP
the date of receipt and acceptance should be inserted later
CR
Field Programmable Gate Array (FPGA) board, which is inexpensive in terms
of computation. Hardware implementation of the Sobel edge detection algo-
rithm is chosen because hardware presents a good scope of parallelism over
software. On the other hand, Sobel edge detection can work with less dete-
US
rioration in high level of noise. A compact study is also been done based on
the previous methods. The proposed architecture uses less number of logic
gates with respect to previous method. Space complexity is also reduced using
proposed architecture.
AN
Keywords FPGA · Edge detection · Sobel operator · Hardware architecture
M
1 Introduction
entity in the image. It also helps in feature extraction and pattern recognition.
Hence, edge detection is of great importance in computer vision. So far, most
of the researchers have chosen software for implementation of basic edge de-
tection algorithms and their variations [2]. But, it has been established that it
PT
Santanu Haldar
Department of Computer Application Kalyani Government Engineering College
Kalyani, Nadia, West Bengal-742101, India
ACCEPTED MANUSCRIPT
T
IP
Fig. 1 Architecture of FPGA board adopted from [4]
CR
presents a scope to parallelize subroutines in a program. Hence, hardware im-
plementation provides much faster alternative as compared to software. In
US
1994 Boo et al. [3] have proposed hardware implementation of edge detection
using Sobel operator using VLSI technology within application specific inte-
grated circuit (IC). In the past few years extensive work has been done in
the area of Field programmable Gate Array (FPGA) based implementation
AN
of edge detection algorithm which in turn implements image processing in
real time. In 2009 real time algorithms have been designed to detect edges on
FPGA board [12]. Parallelism of any algorithm is possible due to integration
of large number of transistors (10k-100k) on a single silicon chip using VLSI
M
technology [10]. All embedded systems are designed and implemented on Ap-
plication Specific Integrated Circuit (ASIC) or FPGA. FPGA is an IC with
Configurable Logical Blocks (CLBs) [5]. CLBs are interconnected using rout-
ing channels on a silicon board based on the desired operation. The internal
ED
anything can go wrong. These programmed ICs are emulated on FPGA board
after correct simulation. In 2007, T.A.Abbasi et al. [1] presented an architec-
ture for Sobel edge detection on FPGA. Later in 2012, this architecture was
CE
T
IP
2 Sobel Edge Detection Algorithm
Sobel Edge detection algorithm is a gradient based edge detection method [6]-
CR
[7], which finds edges using horizontal mask (HM) and vertical mask (VM) [11].
One mask is simply transpose of the other as follows:
−1 −2 −1 −1 0 1
V M = 0 0 0 , HM = −2 0 2
1 2 1
US
−1 0 1
For the convolution process, an image is scanned from left to right and top to
bottom of an image using HM and VM separately. Convolution is the process
AN
multiplying each intensity value of an image with its local neighbors, weighted
by the mask. Let [P ]3×3 be a sub-window of an image, as in figure 2, to be
convolved with HM and VM separately.
The horizontal gradient Gx and the vertical gradient Gy of the center pixel
M
T
1, if G > T
Dop = (4)
0, otherwise
IP
3 Simplification of the Traditional Sobel Edge Detection Algorithm
CR
A few adjustments are required in traditional Sobel edge detection algorithm
because 8-bit architecture has been adopted here for hardware implementation.
In [8], S. Halder et al. simplified the traditional algorithm. Some changes have
US
been done in the simplified version of algorithm proposed by S.Halder et al. [8].
In equation 1, the values of f1 and f2 will be maximum when each of the
contributing pixels of sub-window will have maximum intensity values, i.e.,
255. The same happens with f3 and f4 in equation 2. So, the maximum possible
AN
value of f1 , f2 , f3 and f4 is 4 × 255, thus it will require 10-bit architecture for
implementation.To resolve this issue, values of f1 , f2 , f3 and f4 are limited to
one fourth of the original values. Hence, each of the contributing pixels has
to be divided by 4 before finding out values of f1 , f2 , f3 and f4 , as shown in
M
equations 5 to 8.
1 1 1
f1 = P6 + P7 + P8 (5)
4 2 4
ED
1 1 1
f2 = P0 + P1 + P2 (6)
4 2 4
PT
1 1 1
f3 = P2 + P5 + P8 (7)
4 2 4
CE
1 1 1
f4 = P0 + P3 + P6 (8)
4 2 4
For the same reasons, Gx and Gy has to be divided by 2 and the new equation
for G is given as:
AC
1 1
G= |Gx | − |Gy | (9)
2 2
ACCEPTED MANUSCRIPT
Gx = f1 − f2 (10)
where f1 = ( 81 P6 + 14 P7 + 18 P8 ), f2 = ( 81 P0 + 14 P1 + 18 P2 )
Gy = f3 − f4 (11)
where f3 = ( 18 P2 + 14 P5 + 18 P8 ), f4 = ( 81 P0 + 14 P3 + 18 P6 )
The following four cases have to be considered because the absolute value of
Gx and Gy are calculated in equation 3.
Case 1: If both Gx and Gy are positive.
T
G1 = (f1 − f2 ) + (f3 − f4 )
IP
1 1 1 1 1 1 1 1 1
= P6 + P7 + P8 − P0 − P1 − P2 + P2 + P 5 + P8
8 4 8 8 4 8 8 4 8
CR
1 1 1
− P0 − P3 − P6 (12)
8 4 8
1 1 1 1 1 1
= ( P5 + P7 + P8 ) − ( P0 + P1 + P3 )
4 4 4 4 4 4
= f5 − f6
US
where f5 = ( 41 P5 + 14 P7 + 14 P8 ) and f6 = ( 14 P0 + 41 P1 + 14 P3 )
Case 2: If Gx is positive and Gy is negative.
AN
G2 = (f1 − f2 ) + (f4 − f3 )
1 1 1 1 1
= P6 + P7 + P8 − P0 − P 1
8 4 8 8 4
M
1 1 1 1 1 1 1
− P2 + P 0 + P3 + P6 − P2 − P5 − P8 (13)
8 8 4 8 8 4 8
1 1 1 1 1 1
= ( P3 + P 6 + P7 ) − ( P1 + P2 + P5 )
ED
4 4 4 4 4 4
= f7 − f8
where: f7 = ( 41 P3 + 14 P6 + 14 P7 ) and f8 = ( 14 P1 + 41 P2 + 14 P5 )
Case 3: If Gx is negative and Gy is positive.
PT
G3 = (f2 − f1 ) + (f3 − f4 )
1 1 1 1 1
CE
= P0 + P 1 + P2 − P6 − P 7
8 4 8 8 4
1 1 1 1 1 1 1
− P8 + P 2 + P5 + P8 − P0 − P3 − P8 (14)
8 8 4 8 8 4 8
1 1 1 1 1 1
AC
= ( P1 + P2 + P 5 ) − ( P3 + P6 + P7 )
4 4 4 4 4 4
= f8 − f7
ACCEPTED MANUSCRIPT
G4 = (f2 − f1 ) + (f4 − f3 )
1 1 1 1 1
= P0 + P1 + P2 − P6 − P 1
8 4 8 8 4
1 1 1 1 1 1 1
− P8 + P0 + P 3 + P6 − P2 − P5 − P8 (15)
8 8 4 8 8 4 8
1 1 1 1 1 1
= ( P0 + P 1 + P3 ) − ( P5 + P7 + P8 )
4 4 4 4 4 4
= f6 − f5
T
At a particular instant of time, one out of four cases will be true and rest of the
cases will be false. Suppose, if case 1 is true then f1 and f3 are greater than or
IP
equal to f2 and f4 , respectively. Hence, in that case G1 is greatest among all,
which is considered as resultant gradient, G, of the center pixel (P4 ) of sub-
window. These four cases are exclusive of each other. In turn, it is observed
CR
that the value of G will be the maximum of four possible values,which can be
represented by equation 16.
G = max(G1 , G2 , G3 , G4 )
= max(f9 , f10 ) US
= max(|f5 − f6 |, |f7 − f8 |) (16)
AN
where f9 = |f5 − f6 | and f10 = |f7 − f8 |. Finally, equation 4 is replaced by
equation 17 for deciding whether the center pixel, P4 , is an edge pixel or not.
(
0, if f9 < T and f10 < T
Do p = (17)
M
1, otherwise
4 Methodology
ED
Fig. 3 An image I stored as two-dimensional array, ‘A’, with m rows and n columns
T
IP
CR
US
Fig. 4 Row major and Column major order storage of ’A’(from left to right)
AN
or the equation
Figure 4 shows the ways a two dimensional array, [A]m×n , are represented in
memory by equation 18 and 19.
Figure 5 demonstrates the convolution process. It is clear from the figure that
ED
is stored at the end of the above column in the second iteration. This process
has to be continued till bottom-right corner of an image. Figure 6 shows the
way how a 3 × 3 sub-window of an image can be stored in a linear array using
equation 18.
AC
T
IP
CR
Fig. 6 Group-wise storage of pixels for convolution
US
each iteration. This strategy is expensive in terms of space because information
AN
of a particular pixel is repeated. As seen in figure 6 there are multiple storage
of same pixels, for e.g., pixel at location (0,1) with value 5 has appeared twice.
On the other hand, row-major/column-major order takes less space to store
the pixel information of an image in a linear array. At most m × n entries
M
will be there in this linear array if a two-dimensional array has m rows and
n columns. But, it requires an efficient FPGA based hardware architecture to
extract 9 pixels in each iteration during convolution process. After fetching, 9
ED
T
1: procedure iExtract()
IP
2: //Variable ‘i’ represents row number whereas j represents column number
3: //Variable ‘B’ is the base address of the array
4: //Variable ‘n’ is the total number of the column of an image
5:
CR
6: for i = 1 to n − 2 do
7: Set k = B + i ∗ n
8: for j = 1 to n − 2 do
9: l0 = k − n + j − 1
10: l1 = k − n + j
11:
12:
13:
14:
15:
l2 = k − n + (j + 1)
l3 = k + (j − 1)
l4 = k + j
l5 = k + (j + 1)
l6 = k + n + (j − 1)
US
AN
16: l7 = k + n + j
17: l8 = k + n + (j + 1)
18: end for
19: end for
20: end procedure
M
It is clear from the algorithm that there are three operations namely, sub-
traction, addition and multiplication, involved for finding out indices, to fetch
ED
the intensity values for the convolution process. A FPGA based hardware
architecture is proposed based on the mathematical operations involved in al-
gorithm 1. Figure 8 shows the hardware circuit for finding out the indices.
Adder/subtractor composite block is sufficient for the above specified opera-
PT
tions.
CE
The extracted intensity values Pt = A(lt ) are fed into the next level of FPGA
based architecture as inputs for the convolution process. It is clear from section
AC
T
IP
CR
Fig. 9 Architecture for finding absolute values
US
served that each intensity value for the convolution process has to be divided
AN
by 4. Normally, divider is used for division operation. But, right shift oper-
ator is used here twice to divided each intensity value by 4 because divider
takes more time compare to right shift operator. A 2:1 multiplexer is used for
finding absolute values of |f5 − f6 | and |f7 − f8 | as shown in equation 16 . To
M
find the absolute value the subtraction is done in two ways viz. by subtracting
subtrahend from minuend and by swapping the positions of subtrahend and
minuend as in figure 9. The carry bit of the subtractor block when turns out
to be concludes the result as negative. This carry bit is used as the select line
ED
which reduces the complexity. The carry bits of both the subtractors as shown
in figure 10 are fed into a NAND gate to take the decision for edge pixel. The
truth table of NAND gate suggest that when both the inputs are 1 then only
output is 0 otherwise 1. In other words, when f9 and f10 are less than the
AC
predefined threshold, there will be absence of edge pixel otherwise the corre-
sponding pixel is considered to be an edge pixel.
The final architecture is represented in figure 11, which takes input directly
ACCEPTED MANUSCRIPT
T
from the addressing circuit and computes the edge pixel by comparing gradi-
IP
ent with the threshold. Different components for the convolution process are
depicted above. Figure 11 shows the complete FPGA based architecture for
Sobel edge detection algorithm.
CR
US
AN
M
ED
PT
CE
AC
ACCEPTED MANUSCRIPT
T
IP
CR
US
AN
M
Fig. 11 Proposed circuit for hardware implementation of Sobel edge detection algorithm
ED
The proposed architectures are implemented using VHDL. The program is sim-
ulated followed by synthesis on Xilinx Sparta 6 XC6SLX43TQG144 FPGA
board. The simulation is done on grayscale images of various sizes using a
PT
predefined threshold. Figure 12 shows 8-bit grayscale input images and their
corresponding edge images by hardware and software implementations respec-
tively. In both the cases, same threshold of intensity value 27 has been chosen.
CE
comparisons with existing design have been made in table 2 to show the time
of execution of architectures.
ACCEPTED MANUSCRIPT
T
IP
CR
US
Fig. 12 Row 1: Grayscale images; Row 2: Edges by hardware implementation on FPGA;
Row 3: Edge by software implementation on MATLAB.
AN
Table 1 Device Utilisation Summary
Total Santanu et.al Method [8] Proposed Method
No.of slice registers 4800 49 0
No. of slice LUTs 2400 135 114
M
6 Conclusions
CE
The proposed architecture of Sobel edge detection uses direct indexing of de-
sired pixels unlike the redundant storage of sub-window pixels as in the previ-
ous architectures thus reducing space complexity. The circuit is able to perform
AC
at a faster frequency than existing designs. Hence, the time to process an im-
age is less comparatively. When this architecture is used for large databases it
will show a significant difference. The time complexity of the proposed algo-
ACCEPTED MANUSCRIPT
T
References
IP
1. Tanvir A Abbasi, Mohd Abbasi, et al. A proposed fpga based architecture for sobel
edge detection operator. Journal of Active & Passive Electronic Devices, 2(4), 2007.
2. Fahad M Alzahrani and Tom Chen. A real-time edge detector: algorithm and vlsi
CR
architecture. Real-Time Imaging, 3(5):363–378, 1997.
3. M Boo, E Antelo, and JD Bruguera. Vlsi implementation of an edge detector based on
sobel operator. In EUROMICRO 94. System Architecture and Integration. Proceedings
of the 20th EUROMICRO Conference., pages 506–512. IEEE, 1994.
4. Stephen Brown and Jonathan Rose. Architecture of fpgas and cplds: A tutorial. IEEE
Design and Test of Computers, 13(2):42–57, 1996.
US
5. Stephen D Brown, Robert J Francis, Jonathan Rose, and Zvonko G Vranesic. Field-
programmable gate arrays, volume 180. Springer Science & Business Media, 2012.
6. Richard O Duda, Peter E Hart, et al. Pattern classification and scene analysis, volume 3.
Wiley New York, 1973.
AN
7. Rafael C Gonzalez, Richard E Woods, and Steven L Eddins. Digital image processing
using matlab. 2004.
8. Santanu Halder, Debotosh Bhattacharjee, Mita Nasipuri, and Dipak Kumar Basu. A
fast fpga based architecture for sobel edge detection. In Progress in VLSI Design and
Test, pages 300–306. Springer, 2012.
M
Luis Lázaro Galilea. Embedded vision modules for tracking and counting people. In-
strumentation and Measurement, IEEE Transactions on, 58(9):3004–3011, 2009.
PT
CE
AC