|
|
|
@ -31,7 +31,7 @@ class filter_average(filter):
|
|
|
|
|
kernel = np.ones((5, 5), np.float32) / 25
|
|
|
|
|
self.img = cv.filter2D(self.img, -1, kernel)
|
|
|
|
|
plt.imshow(self.img)
|
|
|
|
|
print("Average filter")
|
|
|
|
|
print("Average")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class filter_blur(filter):
|
|
|
|
@ -41,7 +41,7 @@ class filter_blur(filter):
|
|
|
|
|
def apply(self):
|
|
|
|
|
self.img = cv.blur(self.img, (5, 5))
|
|
|
|
|
plt.imshow(self.img)
|
|
|
|
|
print("Blurring filter")
|
|
|
|
|
print("Normal blur")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class filter_gaussian(filter):
|
|
|
|
@ -51,4 +51,57 @@ class filter_gaussian(filter):
|
|
|
|
|
def apply(self):
|
|
|
|
|
self.img = cv.GaussianBlur(self.img, (5, 5), 0)
|
|
|
|
|
plt.imshow(self.img)
|
|
|
|
|
print("Gaussian filter")
|
|
|
|
|
print("Gaussian blur")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class filter_median(filter):
|
|
|
|
|
def __init__(self, input_file, output_file, img):
|
|
|
|
|
super().__init__(input_file, output_file, img)
|
|
|
|
|
|
|
|
|
|
def apply(self):
|
|
|
|
|
self.img = cv.medianBlur(self.img, 5)
|
|
|
|
|
plt.imshow(self.img)
|
|
|
|
|
print("Median blur")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class filter_erode(filter):
|
|
|
|
|
def __init__(self, input_file, output_file, img):
|
|
|
|
|
super().__init__(input_file, output_file, img)
|
|
|
|
|
|
|
|
|
|
def apply(self):
|
|
|
|
|
kernel = np.ones((5, 5), np.uint8)
|
|
|
|
|
self.img = cv.erode(self.img, kernel, 1)
|
|
|
|
|
plt.imshow(self.img)
|
|
|
|
|
print("Erosion")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class filter_dilate(filter):
|
|
|
|
|
def __init__(self, input_file, output_file, img):
|
|
|
|
|
super().__init__(input_file, output_file, img)
|
|
|
|
|
|
|
|
|
|
def apply(self):
|
|
|
|
|
kernel = np.ones((5, 5), np.uint8)
|
|
|
|
|
self.img = cv.dilate(self.img, kernel, 1)
|
|
|
|
|
plt.imshow(self.img)
|
|
|
|
|
print("Dilatation")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class filter_opening(filter):
|
|
|
|
|
def __init__(self, input_file, output_file, img):
|
|
|
|
|
super().__init__(input_file, output_file, img)
|
|
|
|
|
|
|
|
|
|
def apply(self):
|
|
|
|
|
kernel = cv.getStructuringElement(cv.MORPH_RECT, (3, 3))
|
|
|
|
|
self.img = cv.morphologyEx(self.img, cv.MORPH_CLOSE, kernel)
|
|
|
|
|
plt.imshow(self.img)
|
|
|
|
|
print("Opening")
|
|
|
|
|
|
|
|
|
|
class filter_closing(filter):
|
|
|
|
|
def __init__(self, input_file, output_file, img):
|
|
|
|
|
super().__init__(input_file, output_file, img)
|
|
|
|
|
|
|
|
|
|
def apply(self):
|
|
|
|
|
kernel = cv.getStructuringElement(cv.MORPH_RECT, (3, 3))
|
|
|
|
|
self.img = cv.morphologyEx(self.img, cv.MORPH_OPEN, kernel)
|
|
|
|
|
plt.imshow(self.img)
|
|
|
|
|
print("Closing")
|
|
|
|
|