Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

DSD OPEN ENDED TASK

Div-D

Team members: Swathi v(227) - 01fe18bec194


Swetha G(228) -01fe18bec197
Amit karekar(266) -01fe16bec025
Problem statement: Design a sobel edge detector taking an image as input . Write the
algorithm and implement in Python or C. Then implement the design in Verilog.
Simulation output of Verilog will be an image which will illustrate the edges of the image
input
Objective
To design and implement sobel edge detector using Verilog and python.
Design
 Edge detection
Edge is a location in the image where there is sudden change in the
intensity/colour of pixels. The process of edge detection significantly reduces the amount of
data and filters out unneeded information while preserving the important structural
properties of an image.
 Sobel edge detection
The Sobel operator performs a 2-D spatial gradient measurement on an image and so
emphasizes regions of high spatial frequency that correspond to edges. Typically it is used to
find the approximate absolute gradient magnitude at each point in an input grayscale image.
 The operator is based on convolving the image with 3x3 matrix called kernel.
Suppose that A is an image then using Sobel operator we have:
Gx= -1 0 +1 Gy= -1 0 +1
-2 0 +2 *A -2 0 +2 *A
-1 0 +1 -1 0 +1

As the centre row of kernel is consist of zeros so it does not include the original values of edge
in the image but rather it calculate the difference of above and below pixel intensities of the
particular edge. Thus increasing the sudden change of intensities and making the edge more
visible.
This shows the result of
doing convolution by
placing the Gradient matrix
X over a red marked 100 of
images. The calculation is
shown on the right which
sums up to 400, which is
non-zero, hence there is an
edge. If all m the pixels
of images were of the same value, then the convolution would result in a resultant
sum of zero.

 We calculate the parametric formulas required for applying the Sobel filter:
Gx[i, j] = p[i+1, j-1] + 2 × p[i+1, j] + p(i+1, j+1) – { p[i-1, j-1] + 2 × p[i-1, j] + p(i-1, j+1) }
Gy[i, j] = p[i-1, j+1] + 2 × p[i, j+1] + pi+1, j+1) – { p[i-1, j-1] + 2 × p[i, j-1] + p(i+1, j-1) }
Well, now as you can see there is no p[i,j] in above formulas. Because this element multiplied
to 0 according to Gy and Gx matrices. Sobel Operator is trying to find out the amount of the
difference by placing the gradient matrix over each pixel of our image.
To obtain the value of G we must calculate the following equation.
So ,
G=√ G x 2 +Gy2 or | G |=| Gx |+| Gy |
The angle of orientation of the edge (relative to the pixel grid) giving rise to the spatial gradient
is given by:
In this case, orientation 0 is taken to mean that the direction of maximum contrast from black
to white runs from left to right on the image, and other angles are measured anti-clockwise from
this

General configuration diagram of the system:


Implementation in python:-
import cv2
import numpy as np
from matplotlib import pyplot as plt

# loading image
img0 = cv2.imread('kodi.jpg',)

# converting to gray scale


gray = cv2.cvtColor(img0, cv2.COLOR_BGR2GRAY)

# remove noise
img = cv2.GaussianBlur(gray,(3,3),0)

sobelx = cv2.Sobel(img,cv2.CV_64F,1,0,ksize=5) # x
sobely = cv2.Sobel(img,cv2.CV_64F,0,1,ksize=5) # y
img_sobel = sobelx + sobely

plt.subplot(2,2,1),plt.imshow(img,cmap ='gray')
plt.title('Original'), plt.xticks([]), plt.yticks([])
plt.subplot(2,2,2),plt.imshow(img_sobel,cmap = 'gray')
plt.title('Sobel'), plt.xticks([]), plt.yticks([])
plt.subplot(2,2,3),plt.imshow(sobelx,cmap = 'gray')
plt.title('Sobel X'), plt.xticks([]), plt.yticks([])
plt.subplot(2,2,4),plt.imshow(sobely,cmap = 'gray')
plt.title('Sobel Y'), plt.xticks([]), plt.yticks([])

plt.show()

Original image Sobel

You might also like