Skip to content

Commit a8021b0

Browse files
authored
Update canny.py
1 parent 32f62a8 commit a8021b0

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

canny.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
import matplotlib.pyplot as plt
44
import math
55

6-
6+
#Generating Gaussian Kernel with given sigma
77
def gaussian_kernel(size, sigma=1):
88
size = int(size) // 2
99
x, y = np.mgrid[-size:size+1, -size:size+1]
1010
normal = 1 / (2.0 * np.pi * sigma**2)
1111
g = np.exp(-((x**2 + y**2) / (2.0*sigma**2))) * normal
1212
return g
13-
13+
#Applying sobel filter on image to return a sobel-filtered image and sobel gradient
1414
def sobelfilter(image):
1515
gx = np.array([[1.0, 0.0, -1.0], [2.0, 0.0, -2.0], [1.0, 0.0, -1.0]])
1616
gy = np.array([[1.0, 2.0, 1.0], [0.0, 0.0, 0.0], [-1.0, -2.0, -1.0]])
@@ -26,6 +26,7 @@ def sobelfilter(image):
2626
sobel_filtered_image=sobel_filtered_image/np.max(sobel_filtered_image)
2727
return sobel_filtered_image,Gradient
2828

29+
#Performing NonMaximum Suppresion
2930
def NonMaxSup(Gmag, Grad):
3031
NMS = np.zeros((Gmag.shape[0],Gmag.shape[1]),np.float64)
3132
for i in range(1, Gmag.shape[0] - 1):
@@ -52,6 +53,7 @@ def NonMaxSup(Gmag, Grad):
5253
NMS[i,j] = 0
5354
return NMS
5455

56+
#Threshold Hysteresis
5557
def DoThreshHyst(img):
5658
highThresholdRatio = 0.2
5759
lowThresholdRatio = 0.15
@@ -85,6 +87,7 @@ def DoThreshHyst(img):
8587
GSup = (GSup == 1) * GSup
8688
return GSup
8789

90+
#Integrating all phases of canny edge detection.
8891
def canny_edges(img):
8992
img=cv2.GaussianBlur(img,(5,5),0)
9093
sobelfilterimage,gradient=sobelfilter(img)

0 commit comments

Comments
 (0)