5
5
6
6
7
7
class ConvolutionFilter ():
8
+ """Converts input image to grayscale and applies various convolution filters"""
8
9
9
10
def __init__ (self , image ):
10
11
self .image = cv2 .cvtColor (image , cv2 .COLOR_RGB2GRAY )
@@ -26,6 +27,8 @@ def __init__(self, image):
26
27
[0 , 1 , 0 ]))
27
28
28
29
def __convolution (self , image_roi , kernel ):
30
+ # This function convolves the input kernel on the input image region of interest
31
+
29
32
kernel_dimension = len (kernel )
30
33
pixel_sum = 0
31
34
@@ -40,6 +43,10 @@ def __convolution(self, image_roi, kernel):
40
43
return pixel_sum % 255
41
44
42
45
def __applyFilter (self , kernel ):
46
+ """ Returns convolved image
47
+ Applies the input convolution filter onto the image
48
+ """
49
+
43
50
image = self .image
44
51
filtered_image = np .zeros (image .shape )
45
52
@@ -56,30 +63,31 @@ def __applyFilter(self, kernel):
56
63
return filtered_image
57
64
58
65
def applySharpen (self ):
66
+ """Returns image convolved with Sharpening filter"""
59
67
kernel = self .sharpen
60
-
61
68
filtered_image = self .__applyFilter (kernel )
62
69
return filtered_image
63
70
64
71
def applySobelX (self ):
72
+ """Returns image convolved with SobelX filter"""
65
73
kernel = self .sobelX
66
-
67
74
filtered_image = self .__applyFilter (kernel )
68
75
return filtered_image
69
76
70
77
def applySobelY (self ):
78
+ """Returns image convolved with SobelY filter"""
71
79
kernel = self .sobelY
72
-
73
80
filtered_image = self .__applyFilter (kernel )
74
81
return filtered_image
75
82
76
83
def applyLaplacian (self ):
84
+ """Returns image convolved with Laplacian filter"""
77
85
kernel = self .laplacian
78
-
79
86
filtered_image = self .__applyFilter (kernel )
80
87
return filtered_image
81
88
82
89
def applyCannyEdge (self ):
90
+ """Returns image convolved with CannyEdge filter"""
83
91
84
92
filtered_image = cv2 .Canny (self .image , 50 , 240 )
85
93
return filtered_image
0 commit comments