3.4.1 Introduction

This tutorial introduces you to high-level synthesis (HLS) concepts using SmartHLS. You apply HLS to a real problem, such as synthesizing an image processing application from software written in the C++ programming language. Specifically, you synthesize a circuit that performs one of the key steps of edge detection - a widely used transformation that identifies the edges in an input image and produces an output image showing just those edges. The step you implement is called Sobel filtering. The computations in Sobel filtering are identical to those involved in convolutional layers of a Convolutional Neural Network (CNN).

The following figure shows an example of Sobel filtering applied to an image. This is the image that is used as input data in this tutorial.

Figure 3-1. Sobel Filtering Before and After

Sobel filtering involves applying two 3 x 3 convolutional kernels (also called filters) to an image. The kernels are usually called Gx and Gy, and they are shown in the following figure. These two kernels detect the edges in the image in the horizontal and vertical directions. They are applied separately and then combined to produce a pixel value in the output image at each position in the input image.

The output value is approximated by:

G = |Gx| + |Gy|

Where the Gx and Gy terms are computed by multiplying each filter value by a pixel value and then summing the products together.

Sobel filters and computational action are used to compute one pixel in the output image from an input image.

The bottom of the following image shows an input image with 4 rows and 4 columns, where the value in each cell represents a pixel color. The figure illustrates applying the Sobel filters at one position in the input image to compute one value in the output image. The input image pixels involved in the computation are often referred to as the receptive field.

Figure 3-2. Sobel Filters and Computational Action to Compute One Pixel in the Output Image From an Input Image

A question that might occur to you is: what happens at the edges of the image? That is, the locations where the placement of the 3 x 3 Sobel filters would slide off the edge of the input image. In this tutorial, our program/circuit places 0s into the perimeter of the output image corresponding to such edge locations- this is referred to as padding, and it is a commonly done technique.