Added more opencv image processing filters.

master
Rostislav Lán 2 years ago
parent 7a550057dc
commit 3c0d15f883

@ -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")

@ -64,6 +64,16 @@ class apply_filters:
return flt.filter_blur
elif filter_name == "gaussian":
return flt.filter_gaussian
elif filter_name == "median":
return flt.filter_median
elif filter_name == "erode":
return flt.filter_erode
elif filter_name == "dilate":
return flt.filter_dilate
elif filter_name == "opening":
return flt.filter_opening
elif filter_name == "closing":
return flt.filter_closing
else:
raise ValueError("Invalid filter name")

Loading…
Cancel
Save