DSD Open Ended Task
DSD Open Ended Task
DSD Open Ended Task
Div-D
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
# loading image
img0 = cv2.imread('kodi.jpg',)
# 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()