Hardware Implementation of Sobel Edge Detection Algorithm

. In the ﬁelds of image processing, feature detection, the edge detection is an important aspect. For detection of sharp changes in the properties of an image, edges are recognized as important factors which provides more information or data regarding the analysis of an image. In this work coding of various edge detection algorithms such as Sobel, Canny, etc. have been done on the MATLAB software, also this work is implemented on the FPGA Nexys 4 DDR board. The results are then displayed on a VGA screen. The implementation of this work using Verilog language of FPGA has been executed on Vivado 18.2 software tool.


Introduction
Image processing is a process to carry out some algorithms on a picture , thus to obtain an intensified image and to abstract helpful charactreristics from an image. In this process image is taken as input and characteristics that we want to extract are obtained as output. The approach for finding the margins of an objects in an image is simply referred as edge detection. It operates by diagnosing discontinuities in the intesity of light. In fields like digital image processing, machine vision and computer vision the edge detection method is utilized for extraction of features and segmentation of an image [1].
FPGA is a microcircuit which will be programmed within the area after manufacturing. FPGAs have greater potential application than, programmable ROM (PROM) chips. Because of their structure is in spatial and paralellel way, they are used in real time image processing as implementation platform [2].
The aim of this work is to analyze SOBEL and CANNY edge detection algorithms. The Sobel algorithm is applicable in image processing and computer vision, where it works on the method of approximation of derivative of an image. It is named after Irwin Sobel and Gary Feldman. Sobel algorithm checks the image horizontally and vertically and compute a discrete approximation to the derivative of each pixel. The gradient vector is the result of Sobel operator is stored at respective pixel of image matrix. The image is convolved with the kernal matrix and stores the value of gradient at corrosponding pixel. It is hence comparatively economical in means of calculations. On the contrary , the derivative results that it generates are comparatively unprocessed [3].
The Canny edge detector is a multi-stage detection algorithm which can detect broad range of edges with sup-presion of noise in an images. In 1986 it is discovered by John. F. Canny. He has given a theory of computation of edge detection with the explaination of why the technique works [4].
Canny Edge Detector is considered to be the most efficient edge detector. The canny edge detector is a multistage edge detection algorithm. The steps are Preprocessing, Calculating gradients, Nonmaximum suppression, Thresholding with hysterysis. The two key parameters of the algorithm are an upper threshold and a lower threshold. The upper threshold is used to mark edges that are definitely edges. The lower threshold is to find faint pixels that are actually a part of an edge [1].
The significant increase in processing speed is the major motivation behind hardware image processing. FPGA based design is inherently parallel in nature. FPGA has logic gates, large memory, fast transceivers, analog interfaces, and multicore processors. Due to this the speed of execution increases and it consumes low power too [5].
The primary objective of this work is to match various sorts of edge detection algorithms, analyze the results and find the efficient edge detection algorithm. The aim of finding out sharp changes in intensity of image is to collect significant events. Because of parallel processing the simulation speed is more.
In this work we are implementing digital image processing algorithms. It allows different types of algorithms to be executed on the input file whereas analog image processing doesn't allow so much. It restricts the problems like the of noise and unwanted signal which generally occurs in processing. In this work we are using FPGA boards which have many advantages like faster time to plug , parallel task performance, adaptibility, real time applications.
The rest of the paper is organized as follows. In section 2 literature survey of detection of edge using Sobel and Canny operator is discussed. In section 3 basic concept of edge detection algorithms like Robert Cross Operator, Sobel Operator, Prewitt Operator, Canny Operator is presented briefly. In section 4, flowchart of our work is given. In Section 5, the MATLAB results of sobel, canny and prewitt operators are given along side the implementation of Sobel algorithm on FPGA and therefore the output obtained on VGA screen. Finally, in section 6 we analyze the results and conclusions.

Literature Survey
In [6] the authors have applied edge detection algorithm on images taken by Binocular Microscope. In [7] the authors have implemented Sobel and Canny algorithms on X-ray images of teeth to find its edges. In [8] the author applied various types of edge detection algorithm in Robot assembly system and compared the results. In [9] the edges of license plate has been compared using different image enhancement filters. The objective of [10] is to provide an algorithm for obtaining the edges in medical field. In [11] authors have applied efficient edge detection on real time video processing using FPGA. In [12] authors have implemented parallel architecture of Sobel edge detection in FPGA. [13] deals with model based approach by performing edge detection using FPGA. In [14] authors have implemented real time canny edge detection using FPGA. In [15] authors have implemented of real time color image edge detection.
In [16] by sensing the data from forward looking optical and active W-band radar sensors, the boundaries of road and lane has been detected automatically. In [17] author described the detection and coding of visually important edges which leads to a new edge detection system. [18] deals with edge detection SAR images for road network extraction. [19] distinguishes the surface temprature by applying edge detection on the satellite images. In [20] authors have implemented Fuzzy sets of X-ray images by detecting the edges . [21] deals with mathematical morphology of medical images. [22] uses Xilinx system generator for implementing FPGA on MRI image filtering and tumor characteristics. [23] uses fusion of colors and edge information to detect and locate the people in video image. [24] describes scan line approximation by detecting the edge. In [25] based on unsupervised classification of edge authors have implemented detection of text in an image.

Edge detection algorithms
To identify and locate sudden changes in an image, the edge detection method is used.In simple words it is used to determine local change in the intensity of an image or the gradient of an image intensity. In image processing areas edge detection is an elemntary mechanism used to get the characteristics or data from the pixel. The process of edge detection has been used by object recognition, target tracking, segmentation, data compression, image reconstruction and so on. The original image is transformed into edge image by using edge detection method by introducing grey effect in the image [26].
The different kinds of edge detection algorithms are explained as follows:

Robert Cross Operator
To perform simple, easy and quick to compute gradient of an image, the Robert Cross Algorithm is generally used.This operator utilizes a pair of 2X2 convolution masks (1). One kernel or mask is rotated by 90 degrees of other. Thus it calculates the value of gradient by using diagonal direction approach.The approximated absolute value of the gradient is shown in the result at each pixel [27].

Sobel Operator
Gradient of thr image intensity ia calculated by Sobel operator at each pont. In first derivative of an image, the sobel operator searches for maximum and minimum gradient values. The gradient has certain magnitude as well as direction. The value of gradient of the pixel is then calculated in a black and white image. It uses 2 kernels with 2 directions i.e. x and y [28]. They are also known as convolution masks. If A is the image matrix and horizontal and verical kernels which carry out the convolution are G x and G y shown in (2).

Prewitt Operator
Prewitt operator has the same equation that are used by sobel operator with the constant c=1. The mask for Prewitt operator is shown in (3) . It is analogous to Sobel operator.It is computationally less expensive and faster method for edge detection. These operators are only applicable for noiseless and well contrasted image.Thus it is sensitive to noise, and are imprecise [30].

Canny Operator
The objective of Canny Edge Detection Algorithm is to reduce the amount of noise present in detected image. It is the optimal algorithm among the all algorithms mentoined above. The three main characteristics of the canny edge detection are as follows: • Low error rate: Non-edge should not be appeared in detected image or edge occurring in image should not be missed.
• Good Localization: The distance between the actual edge and detected edge must be less.
• Single Response: There shouldn't be many responses for a single edge [31].
The process of canny edge algorithm is divided into four steps: 1. Smoothing: The removal of noise or unwanted signal from an image is called as Smoothing.For this purpose Gaussian filter is applied. The Gaussian filter with size 5x5 is used to filter out the unwanted edges or signal. The filter is convolved with an image matrix to reduce the effect of false detection.
2. Finding gradient: To find out the value of gradient of pixel, canny edge detector uses any operator like prewitt, robert or sobel. In both horizontal and vertical direction, it calculates the value of first derivative and returns to that corresponding pixel. Along with edge gradient, direction of an edge has taken under consideration.
3. Non maximum suppression: Appearance of sharp and thin lines in detected image corresponds to the greater efficiency. Thus this step is used for edge thinning purpose. According to the third criteria, single edge must have single response. Thus this process removes the unwanted pixels which should not be appeared as an edge.

Hysteresis:
Mostly all edge detection operators use only one threshold but canny uses double threshold.
To store the high gradient value pixel and remove the low gradient value pixel in order to get the more accurate real edges, double threshold is used named as upper and lower. The edges that are going to express or supress is defined by two thresholds and conditions for that are as follows: • The edge will express only if its value is more than upper threshold.
• The edge will suppress only if its value is less than lower threshold.
• If the pixel value lies in between two thresholds i.e. upper and lower, then edge will only expressed if it is connected to another edge which has higher value of pixel than upper threshold [7]. Our work is divided in two parts as follows:

Flow chart
1. MATLAB simulation: In this part firstly we have written Matlab code for Sobel and Canny algorithms. Using that code we run the simulation on MATLAB software. After this step we got output for SOBEL and CANNY. We observed the outputs and compared the results of both the algorithms.

FPGA implementaion:
In this part we have written Verilog code for Sobel algorithm in Vivado software tool. For Image Processing on FPGA following steps are executed as shown in Figure 3. Firstly we have to convert original image file which is in jpeg or bmp format in coe, mif or txt format. For our project we have converted jpeg file into coe file. After this image processing algorithm is applied on the image. The output file is again converted into jpeg or bmp format to see the output. After this step we have sythesized the Verilog code for Sobel algorithm on Vivado software tool and generated RTL design. Then we implemented it on Nexys 4 DDR FPGA board. Then we observed the output on VGA screen and comapred with the MATLAB output.  Figure 4 shows the block diagram of the work. In computer Verilog code for edge detection is run using Vivado software tool. It is then transferred to Nexys 4 DDR Board using JTAG cable. After successfully implementing the code the output is obtained on VGA screen through VGA Cable.

MATLAB Result
The original image is shown in Figure 5. Sobel, Canny and Prewitt edge detection operator simulation outputs are shown in Figure 6, Figure 7 and Figure 8 respectively.

FPGA Result
Sobel edge detection algorithm has been implemented on FPGA using Nexys 4 DDR board and Vivado 18.1 software.

Conclusion
From the MATLAB result, we have observed that Canny operator produces sharp edge with the smooth continuous pixels. Sobel and Prewitt edge detection algorithms cannot produce sharp edges as compared to Canny algorithm. From our analysis, output obtained by Canny operator is better than the output of Sobel and Prewitt edge detection operators. Also we have implemented Sobel algorithm on Nexys 4 DDR FPGA board and compared the results with MATLAB results.

Future Scope
Further we can implement this operation for Canny algorithm as well. Real time image processing is also possible using Camera.