diff --git a/src/filters.py b/src/filters.py index e07fafe..2567186 100644 --- a/src/filters.py +++ b/src/filters.py @@ -10,15 +10,13 @@ import cv2 as cv # Parent class for all the filters class filter: - def __init__(self, input_file, output_file, img): - self.input_file = input_file - self.output_file = output_file + def __init__(self, img): self.img = img - + class average(filter): - def __init__(self, input_file, output_file, img): - super().__init__(input_file, output_file, img) + def __init__(self, img): + super().__init__(img) def apply(self): kernel = np.ones((3, 3), np.float32) / 9 @@ -26,51 +24,52 @@ class average(filter): class blur(filter): - def __init__(self, input_file, output_file, img): - super().__init__(input_file, output_file, img) + def __init__(self, img): + super().__init__(img) def apply(self): self.img = cv.blur(self.img, (3, 3)) class gaussian(filter): - def __init__(self, input_file, output_file, img): - super().__init__(input_file, output_file, img) + def __init__(self, img): + super().__init__(img) def apply(self): self.img = cv.GaussianBlur(self.img, (3, 3), 0) class median(filter): - def __init__(self, input_file, output_file, img): - super().__init__(input_file, output_file, img) + def __init__(self, img): + super().__init__(img) def apply(self): self.img = cv.medianBlur(self.img, 1) class bilateral(filter): - def __init__(self, input_file, output_file, img): - super().__init__(input_file, output_file, img) + def __init__(self, img): + super().__init__(img) def apply(self): self.img = cv.bilateralFilter(self.img, 1, 75, 75) class denoise(filter): - def __init__(self, input_file, output_file, img): - super().__init__(input_file, output_file, img) + def __init__(self, img): + super().__init__(img) def apply(self): pass #does not work - #img = cv.cvtColor(self.img, cv.COLOR_GRAY2BGR) - #self.img = cv.fastNlMeansDenoisingColored(img, h=3) + self.img = np.uint8(self.img) + self.img = cv.fastNlMeansDenoising( + self.img, h=10, searchWindowSize=21, templateWindowSize=7) class sharpen(filter): - def __init__(self, input_file, output_file, img): - super().__init__(input_file, output_file, img) + def __init__(self, img): + super().__init__(img) def apply(self): kernel = np.array([[0, -1, 0], [-1, 5, -1], [0, -1, 0]]) @@ -78,8 +77,8 @@ class sharpen(filter): class erode(filter): - def __init__(self, input_file, output_file, img): - super().__init__(input_file, output_file, img) + def __init__(self, img): + super().__init__(img) def apply(self): kernel = np.ones((3, 3), np.uint8) @@ -87,8 +86,8 @@ class erode(filter): class dilate(filter): - def __init__(self, input_file, output_file, img): - super().__init__(input_file, output_file, img) + def __init__(self, img): + super().__init__(img) def apply(self): kernel = np.ones((3, 3), np.uint8) @@ -97,8 +96,8 @@ class dilate(filter): # Erosion, then dilatation class opening(filter): - def __init__(self, input_file, output_file, img): - super().__init__(input_file, output_file, img) + def __init__(self, img): + super().__init__(img) def apply(self): kernel = cv.getStructuringElement(cv.MORPH_RECT, (3, 3)) @@ -107,8 +106,8 @@ class opening(filter): # Dilatation, then erosion class closing(filter): - def __init__(self, input_file, output_file, img): - super().__init__(input_file, output_file, img) + def __init__(self, img): + super().__init__(img) def apply(self): kernel = cv.getStructuringElement(cv.MORPH_RECT, (3, 3))