Skip to content

Commit 0372d02

Browse files
committed
Commented Filtering code
1 parent 421fa3c commit 0372d02

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

Image_Filters/ConvolutionalFilters.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66

77
class ConvolutionFilter():
8+
"""Converts input image to grayscale and applies various convolution filters"""
89

910
def __init__(self, image):
1011
self.image = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
@@ -26,6 +27,8 @@ def __init__(self, image):
2627
[0, 1, 0]))
2728

2829
def __convolution(self, image_roi, kernel):
30+
# This function convolves the input kernel on the input image region of interest
31+
2932
kernel_dimension = len(kernel)
3033
pixel_sum = 0
3134

@@ -40,6 +43,10 @@ def __convolution(self, image_roi, kernel):
4043
return pixel_sum % 255
4144

4245
def __applyFilter(self, kernel):
46+
""" Returns convolved image
47+
Applies the input convolution filter onto the image
48+
"""
49+
4350
image = self.image
4451
filtered_image = np.zeros(image.shape)
4552

@@ -56,30 +63,31 @@ def __applyFilter(self, kernel):
5663
return filtered_image
5764

5865
def applySharpen(self):
66+
"""Returns image convolved with Sharpening filter"""
5967
kernel = self.sharpen
60-
6168
filtered_image = self.__applyFilter(kernel)
6269
return filtered_image
6370

6471
def applySobelX(self):
72+
"""Returns image convolved with SobelX filter"""
6573
kernel = self.sobelX
66-
6774
filtered_image = self.__applyFilter(kernel)
6875
return filtered_image
6976

7077
def applySobelY(self):
78+
"""Returns image convolved with SobelY filter"""
7179
kernel = self.sobelY
72-
7380
filtered_image = self.__applyFilter(kernel)
7481
return filtered_image
7582

7683
def applyLaplacian(self):
84+
"""Returns image convolved with Laplacian filter"""
7785
kernel = self.laplacian
78-
7986
filtered_image = self.__applyFilter(kernel)
8087
return filtered_image
8188

8289
def applyCannyEdge(self):
90+
"""Returns image convolved with CannyEdge filter"""
8391

8492
filtered_image = cv2.Canny(self.image, 50, 240)
8593
return filtered_image

Image_Filters/NoiseReduction.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66

77
class NoiseReduction():
8+
"""Converts input image to grayscale and reduces noise in the image"""
89

910
def __init__(self, image):
1011
self.image = image
@@ -14,6 +15,8 @@ def __init__(self, image):
1415
self.largeBlur = np.ones((21, 21), dtype="float") * (1.0 / (21 * 21))
1516

1617
def __convolution(self, image_roi, kernel):
18+
# This function convolves the input kernel on the input image region of interest
19+
1720
kernel_dimension = len(kernel)
1821
pixel_sum = 0
1922

@@ -28,6 +31,10 @@ def __convolution(self, image_roi, kernel):
2831
return pixel_sum % 255
2932

3033
def __applyFilter(self, kernel):
34+
""" Returns convolved image
35+
Applies the input convolution filter onto the image
36+
"""
37+
3138
image = self.image
3239
kernel_dimension = len(kernel)
3340
kernel_margin = kernel_dimension//2
@@ -47,21 +54,24 @@ def __applyFilter(self, kernel):
4754
return filtered_image
4855

4956
def applySmallBlur(self):
57+
"""Returns image applied with small blur filter"""
58+
5059
kernel = self.smallBlur
5160
image = self.image
52-
5361
blured_image = cv2.filter2D(image, -1, kernel)
5462
return blured_image
5563

5664
def applyLargeBlur(self):
65+
"""Returns image applied with large blur filter"""
66+
5767
kernel = self.largeBlur
5868
image = self.image
59-
6069
blured_image = cv2.filter2D(image, -1, kernel)
6170
return blured_image
6271

6372
def applyGaussianBlur(self):
64-
image = self.image
73+
"""Returns image applied with Gaussian blur filter"""
6574

75+
image = self.image
6676
filtered_image = cv2.GaussianBlur(image, (9, 9), 0)
6777
return filtered_image

0 commit comments

Comments
 (0)