0.edge Detection - Sobel Algorithm (8 Files Merged)
0.edge Detection - Sobel Algorithm (8 Files Merged)
• Edge detection includes a variety of mathematical methods that aim at identifying edges and
curves in a digital image at which the image brightness changes sharply or, more formally,
has discontinuities.
• The same problem of finding discontinuities in one-dimensional signals is known as step
Edge Detection Algorithms detection and the problem of finding signal discontinuities over time is known as change
detection.
• Edge detection is a fundamental tool in image processing, machine vision and computer vision,
particularly in the areas of feature detection and feature extraction.
Dr Arunachalam V
Associate Professor, SENSE
• Examples: Sobel operator, Prewitt operator, Robert operator • It computes the gradient approximation of the image intensity function for image edge detection.
• Gaussian-based operator which computes second-order derivations in a digital image. • It uses two 3 × 3 kernels/convolution masks, which are convolved with the input image to
calculate the vertical (𝑆𝑥 ) and horizontal (𝑆𝑦 ) derivative approximations.
• Examples: Canny edge detector, Laplacian of Gaussian
−1 0 +1 +1 +2 +1
• 𝑆𝑥 = −2 0 +2 𝑆𝑦 = 0 0 0
−1 0 +1 −1 −2 −1
5 0 30 30 0 -30
• The gradient in x direction, (𝑆𝑥 ) using filter 𝑠𝑥 • Calculate the gradient Magnitude = 𝑆𝑥 2 + 𝑆𝑦 2
i.j 1 2 3 4 5 i.j 1 2 3 4 5 The pixels, (1,2), (2,2), (3,2), (4,2) and (5,2) are
1 0 -10 -30 -40 -30 1 0 31.62 42.43 40 42.43 larger values than (1,1), (2,1), (3,1), (4,1) and
2 0 0 0 0 0 2 0 40 40 0 40 (5,1) therefore (1,2), (2,2), (3,2), (4,2) and (5,2)
3 0 0 0 0 0 3 0 40 40 0 40 are the edge pixels.
4 0 0 0 0 0 4 0 40 40 0 40
References
• Canny Edge Detector (justin-liang.com)
• Sobel Edge Filter. We can think of an image, which is… | by Shailesh
Kumpawat | Analytics Vidhya | Medium
• Week 4: Image Filtering and Edge Detection (sbme-tutorials.github.io)
• Canny edge detector – Wikipedia Sobel edge detection - IP
• MATLAB - Image Edge Detection using Sobel Operator from Scratch -
GeeksforGeeks Dr Arunachalam V
Associate Professor, SENSE
Image Smoothening 𝑆𝑦 1 2 3 4 5
I 1 2 3 4 5 𝐺𝑥 1 2 3 4 5
• Kernel used for the smoothening is a 5 × 5 gaussian kernel. 1 21 64 128 178 144
1 0 2 15 0 0 1 2 4 5 4 2
2 30 90 174 231 181
2 0 0 0 4 60 2 4 9 12 9 4
1/159 3 20 56 99 121 88
3 0 10 16 119 238 3 5 12 15 12 5
4 -6 -23 -57 -89 -77
Original Image Image after smoothening 4 0 14 170 255 255 4 4 9 12 9 4
- - - -
5 0 98 255 255 255 5 2 4 5 4 2 5 -41
120 228 299 233
𝑀 1 2 3 4 5 𝑆𝑥 1 2 3 4 5
1 30 80 140 180 164 1 -20 -47 -57 -26 78
2 62 147 220 237 262 2 -54 -116 -135 -54 190
3 89 188 223 139 300 3 -87 -179 -199 -69 287
4 96 190 207 107 306 4 -96 -189 -199 -59 296
5 77 172 259 300 300 5 -65 -123 -124 -30 189
𝑀𝑆𝑜𝑏𝑒𝑙 1 2 3 4 5 𝑀𝑆𝑚𝑜𝑜 1 2 3 4 5
1 4 30 4 74 124 1 30 80 140 180 164
2 14 35 172 579 610 2 62 147 220 237 262
3 36 282 761 1049 811 3 89 188 223 139 300
4 162 738 1025 657 899 4 96 190 207 107 306
5 210 708 824 938 1081 5 77 172 259 300 300
• Camera interface module decodes the incoming video stream from the camera and
performs the colour space conversion (YCrCb to RGB). Finally, it converts 24-bit
RGB data into 8-bit grey data. • Therefore, 8-bit grey pixel data coming from the camera interface module cannot
be processed directly. It must be stored in FPGA memory before processing.
• DVI module uses edge information (output of edge detection module) and video
timing signals information (from camera interface) to display the edge detected • The gradient computation module uses eight neighborhoods pixels coming from
video stream on the display monitor. buffer memory for computing the approximate gradient value which is the sum of
absolute values of horizontal and vertical gradients.
• For the Sobel edge detector, there are three main modules: Sobel buffer memory,
gradient computation module, and edge map module. • Edge map module is a simple comparator which compares the gradient value
(GRD) with a user-defined threshold (TH).
• Sobel edge detector is a window-based operator which requires pixel
neighbourhood information for computing the edge map of a particular pixel.
Case 2: Case 3:
Case 4: None Max Suppression Image
• The logic behind Histogram Equalization is that the image with the best visual appearance is the 5 4 6 7 • Total Number of pixels = 16
one whose histogram looks like the regular distribution. • Probability = No. of Pixels/ Total Number of pixels (16)
• Cumulative probability = Current Probability + (Previous Cum. Probability)
• A Cumulative Distribution Function(CDF) of a histogram is the fraction of pixels with a pixel
value that is less than or equal to the specified pixel value. Histogram Equalization
Original Pixel 1 2 3 4 5 6 7 8 9 10
8 5 11 13
• Histogram Equalization is particularly useful in cases where both backgrounds and foregrounds Intensity
are both bright or dark. Probability 0.0625 0.1875 0.1875 0.125 0.125 0.0625 0.1875 0.0625 0 0
18 18 20 5
Cum.Probability 0.0625 0.25 0.4375 0.5625 0.6875 0.75 0.9375 1 1 1
Improved pixel by 1 5 8 11 13 15 18 20 20 20
13 11 15 18 Rounding HE
Contrast Stretching
• In Contrast Stretching the contrast in an image is stretched from the range of intensity values it
contains to span a desired range of values.
• It is also called Normalization.
• Some Contrast Stretching techniques include:
• Minimum-Maximum,
• Percentage, and
• Piecewise Contrast Enhancement.
Where min and max are the maximum and minimum pixel values in the image.
RGB Color Model
• The RGB colour model is an additive colour model in which red, green and blue light are added
together in various ways to reproduce a broad array of colours.
• The name of the model comes from the initials of the three additive primary colours, red, green,
and blue.
Contrast enhancement using RGB to HSV HSV / HSB Color Model
algorithm • HSV – (Hue, Saturation, Value), also known as HSB (Hue, Saturation, Brightness).
• It is often more natural to think about a colour in terms of hue and saturation than in terms of
additive or subtractive colour components.
• HSV is a transformation of an RGB colour space, and its components and colourimetry are relative
to the RGB colour space from which it was derived.
References
Example 2 • Embedded Motion Control 2012 Group 8 - Control Systems Technology Group
• Input : r, g, b = 45, 215, 0 (tue.nl)
Output : h, s, v = 107.44, 100.0, 84.3 • Program to Change RGB color model to HSV color model – GeeksforGeeks
• Types of Contrast Enhancement Algorithms and Implementation in Python
(opengenus.org)
Example 3
• (2) (PDF) Digital image enhancement by brightness and contrast manipulation
• Input : r, g, b = 31, 52, 29 using Verilog hardware description language (researchgate.net)
Output : h, s, v = 197, 31.11, 17.64
Traffic Light Controller (TLC) Design on FPGA A Structure of TLC Design on FPGA
• TLC design system is composed of a finite state machine (FSM), data storage (D_RAM), timer,
divider, and various synchronizers (latch, and synchronizer) as declared in the following: EN-W
L0-L1
• Finite State Machines (FSM) are the core of the traffic light controller system. It controls the loading of ADD-IN HEX-
F0-F1 D_RAM
CIN0-CIN4 Display
static data storage locations with timing parameters, reading RAM locations to display these parameters
and controls the actual traffic lights. GO
• D_RAM: This component is used to store the timing parameters. Depending on the signal en_w, select FSM
TS1-TS3 Traffic light (0-13)
to read the contents by L0-L1 switches, or write new timing parameters by C0-C4 switches and display
ADD_OUT
the contents on the HEX_LEDs.
• A divider is used to generate the clock (1 MHz) for an overall system from 50 MHz of the chip FPGA
LATCH
Spartan 3E. WR
• Sec_pulse is used to generate a one-second clock, which is used in the timing of the traffic lights.
• A timer is implemented as a counter Divider SEC_PULSE TIMER
• Latch: A pedestrian signal is latched so that when the user pushes the button once, the signal is queued
until the FSM needs it.
CLKS
• Sensors: There are three traffic sensors which are synchronized by simply passing it through a flip flop.
State Diagram
4-Way Traffic Light Controller Based on FSM
• There are eight states in the state diagram which
• There are four roads: East, North, West, and are green and yellow states for each road.
South. • In the green state of a road, only that road will be
• The green light will go on circularly in the green, others will be red.
counter-clockwise direction. • The system will remain for 20 seconds in this
• The green light will remain on for 20 state.
seconds. • In the yellow state of a road, the corresponding
• In this period all other roads will be red. Then, road will be yellow, the next road to be green will
the yellow light will light up and the next road be red-yellow and others will be red.
to be green will be in a red-yellow state to • The system will remain for 4 seconds in this
caution the drivers. state. The states of the system will rotate as
• The system will be in this state for 4 seconds. shown in the figure.
• Similarly, the jam condition is implemented using a 4-bit variable Jam. It’s operation is like
that of the emergency condition.
State State LA LB
(Binary)
S0 00 Green Red
S1 01 Yellow Red
S2 10 Red Yellow
S3 11 Red Green
Verilog Code Moore FSM (Main Module)
Logic Circuit
References
• GitHub - raash1d/smart-traffic-light-controller: A Mealy Finite State Machine (FSM), developed in
Verilog, designed to control traffic lights at a crossroad having a major road (main road) and a
minor road (side road).
• PPT - Lecture 5. Verilog HDL #3 PowerPoint Presentation, free download - ID:2396169
(slideserve.com)
• Verilog code for Traffic light controller - FPGA4student.com
Real Time Clock (RTC)
• RTC is an IC(integrated circuit) device and a computer clock that keep track of the current time.
• It assists to keep and maintain accurate time in devices.
• It is powered by an internal lithium battery.
• As a result of which even if the power of the system is turned off, the RTC clock keeps running.
Real Time Clock
Dr Arunachalam V
Associate Professor, SENSE
• RTC maintains its clock by counting the cycles of an oscillator — usually an external 32.768kHz
crystal oscillator circuit, an internal capacitor-based oscillator, or even an embedded quartz crystal. • A real-time clock (RTC) is an electronic device designed in the form of an integrated circuit to
measure the passage of real-time.
• Some can detect transitions and count the periodicity of an input that may be connected.
• Real-time clocks maintain accurate time measurements within an embedded system even when the
• Many RTCs can detect this change-over and go into an ultra-low power state where they power
main power is off.
down all circuitry except those essential for maintaining the clock in order to conserve battery life.
• It counts hours, minutes, seconds, months, days, and even years.
• RTCs can also include alarm functions — set times that when reached trigger the RTC to drive an
output that wakes the processor up. • These modules can be found in nearly every electronic device especially when the device requires
a form of accurate timekeeping.
• A real-time clock (RTC) is an electronic device designed in the form of an integrated circuit to
measure the passage of real-time.
• The need for accurate timekeeping is often used as a trigger for specific events.
• The reason independent power is necessarily comes down to the functional use of RTC modules in
laptops, computers, tablets, and other electronic devices.
(or)
FPGA
References
• Role of RTC(Real Time Clock) in Embedded Devices | by Iqram Ali | Medium
• What is a Real-Time Clock (RTC) and Why are They Important in Computing? - History-Computer
• How to Use a Real-time Clock Module with the Arduino - Circuit Basics
• GitHub - superzanti/Verilog_Clock: A real time clock written in Verilog for the Spartan-3AN FPGA
by Xilinx. This clock includes date and 24-hour time with an alarm clock. Interfacing & Programming
• DS1307.pdf (analog.com) Video Graphics Array (VGA) module
Dr Arunachalam,
Associate Professor, SENSE
Introduction
VGA - Resolution
• The Video Graphics Array (VGA) connector is a standard connector used for computer video
output.
• VGA is slowly replaced by other displays such as DVI, HDMI, and DisplayPort.
• 15-pin connects to PCs, as well as many monitors, projectors and high-definition television sets.
• The HDMI specification is very detailed, so interfacing directly from an FPGA to an HDMI
• The Video Graphics Array (VGA) interface is common to most modern computer displays and is
display is more of a challenge than a VGA display.
based on a pixel map, color planes and horizontal and vertical sync signals.
• The resolution of the screen can vary from 480 × 320 up to much larger screens, but a
• A VGA monitor has three color signals (red, green and blue) that set one of these colors on or off
standard default size is 640 – 480 pixels.
on the screen.
• This is 480 lines of 640 pixels in each line, so the aspect ratio is 640/480 leading to the classic
• The intensity of each of those colors sets the final color seen on the display.
landscape layout of a conventional monitor screen.
A digital monitor keeps the timing of the sync signals w.r.t the resolution. Also, sets up some ADCs to
sample the voltages of the RGB lines.
Industry Standard Timing
Timing parameters for the 640×480 resolution VGA Signal 640 x 480 @ 60 Hz
Control signals
Active Area, Horizontal Blanking, Vertical Blanking
• The two control signals Horizontal Sync (H_Sync) and Vertical Sync (V_Sync).
• H_Sync is high when frame area is horizontally active, and it activates the vertical
blanking area of the frame.
• V_Sync is high when frame area is vertically active, and it activates the horizontal
blanking area of the frame.
• Therefore, if H_Sync and V_Sync are both high, then the frame area is active on both
horizontally and vertically.
• VGA monitors were Cathode Ray Tubes (CRTs).
• Due to the way CRT displays work, it deals with the Front Porch and Back Porch.
• These allows the active area to be shifted around the VGA monitor.
VGA Signal Timing VGA Signal Timing
• Video data at 60 Hz, means 60 frames per second.
• The refresh rate for the display is fixed at 60 Hz, which is the typical value used in monitors.
• Using an active area of 640 by 480, meaning 640 columns and 480 rows in the active area.
• In order to achieve this refresh rate on a 640×480 pixel screen, the pixel rate calculation is done as
follows: • There are a total of 794 columns and 525 rows in the total frame.
• Pixel Rate = Total Horizontal Pixels × Total Vertical Lines × Number of frames per second • This is a total of 794×525=416,850 pixels.
= 800 × 525 × 60 = 25 MHz • Board uses a 25 MHz clock. So if you draw one pixel per clock cycle, how much time does it take
to draw an entire frame?
416850/25000000 = 0.01667 seconds.
Dr Arunachalam, • LCDs allow displays to be much thinner than cathode ray tube (CRT) technology. LCDs consume
much less power than LED and gas-display displays because they work on the principle of
Associate Professor, SENSE
blocking light rather than emitting it.
• Where an LED emits light, the liquid crystals in an LCD produce an image using a backlight.
• As LCDs have replaced older display technologies, LCDs have begun being replaced by new
display technologies such as OLEDs.
Introduction
Character LCD
• A display is made up of millions of pixels. The quality of a display commonly refers to the number
of pixels. • Character LCDs are ideal for displaying text.
• For example, a 4K display is made up of 3840×2160 or 4096 × 2160 pixels. A pixel is made up of • They can also be configured to display small icons, but the icons must be only 7×5 pixels.
three subpixels; red, blue and green- commonly called RGB. • In character LCD, the little rectangles where the characters are displayed.
• When the subpixels in a pixel change colour combinations, different colours can be produced. • Each rectangle is a grid of pixels.
• With all the pixels on a display working together, the display can make millions of different
colours.
• A picture is created when the pixels are rapidly switched on and off.
Graphical LCD 2 line × 16 characters- LCD module
• The graphical LCD has one big grid of pixels (in this case 128x64) - It can display text but its best
• An LCD screen is an electronic display module that uses liquid crystal to produce a visible image.
at displaying images.
• The 16×2 LCD display is a very basic module commonly used. The 16×2 translates a display of 16
• Graphical LCDs tend to be larger, more expensive, difficult to use and need many more pins
characters per line in 2 such lines.
because of the complexity added.
• In this LCD, each character is in an 8×5 matrix.
• Pin6 (Enable):
• Is display can work on two modes like 4-bit & 8-bit
• This enables the pin must be high to perform the Read/Write procedure. • These are obtainable in Blue & Green Backlight
• This pin is connected to the data pin of the microcontroller to be held high constantly.
• It displays a few custom generated characters
• Pin7 to 14 (Data Pins):
• The data pins are connected through the microcontroller for data transmission.
• The LCD module can also work on the 4-bit mode using only pins 0, 1, 2 & 3.
Interfacing an FPGA with 16×2 LCD Displaying “HELLO WORLD!” with 16×2 LCD
• FSM has two inputs (addr_reg and cnt_reg) and five outputs (s1, s2, RS, RW, and E). • The “HELLO WORLD!” message has 12 characters, and we can use a 12 × 8-bit ROM to store the
• The FSM inputs allow us to monitor the status of the “Path 1” and “Path 2” blocks. message.
• The “s1” output controls “Path 1” and, consequently, the data applied to the DB7-DB0 pins. • However, let’s consider a 16 × 8-bit ROM for the message so that we can display messages as long
as 16 characters (the length of the first row of the LCD).
• The “s2” output controls the “Path 2” block and can be used to generate the required time delays.
• In figure, it shows a 20 × 8-bit ROM if our message is at most 16 characters long.
• The “RS”, “RW”, and “E” outputs generate the appropriate waveforms for the LCD control pins.
• These additional four bytes will be used to store the data related to the LCD instructions that allow
us to configure the module.
• the building blocks for interfacing an FPGA with a common 16x2 LCD module requires ROM,
some DFFs, and multiplexers. Additionally, needs an FSM to control these building blocks.
LCD module - Video display & Touch sensitive
• Use the following link to explore more on interfacing Graphical LCD with Touch-sensitive display
with an FPGA:
• PIO – Parallel IO • https://www.intel.com/content/www/us/en/content-details/653846/an-527-lcd-controller-
• SPI – Serial Peripheral Interface replacement.html
• MAX II – Voltage converter
• Some of the major steps are:
FPGA 2.5 V to LCD 3.3 V
• Add custom instructions to the NIOS II processor to accelerate the application
• Add hardware accelerator modules to accelerate the application
• Add custom hardware to the LCD controller to accelerate graphical operations
• Implement burst access in DMA modules to optimize memory bandwidth
References
• https://www.allaboutcircuits.com/technical-articles/how-to-interface-mojo-v3-fpga-board-16x2-
lcd-block-diagram-Verilog-code/
• https://www.fpga4fun.com/TextLCDmodule.html
• https://www.watelectronics.com/lcd-16x2/
• https://www.electronicsforu.com/technology-trends/learn-electronics/16x2-lcd-pinout-diagram
• https://www.mouser.in/applications/programmable-logic-display/
• https://www.elprocus.com/interface-lcd-liquid-crystal-display-using-arduino/
• https://www.elprocus.com/lcd-16x2-pin-configuration-and-its-working/
• https://www.intel.com/content/www/us/en/content-details/653846/an-527-lcd-controller-
replacement.html