diff --git a/src/__pycache__/filters.cpython-310.pyc b/src/__pycache__/filters.cpython-310.pyc new file mode 100644 index 0000000..c49239f Binary files /dev/null and b/src/__pycache__/filters.cpython-310.pyc differ diff --git a/src/filters.py b/src/filters.py new file mode 100644 index 0000000..2d39235 --- /dev/null +++ b/src/filters.py @@ -0,0 +1,48 @@ +"""! @file filters.py +@brief Filter library for the application +@author xlanro00 +""" + +import numpy as np +import matplotlib.pyplot as plt +import cv2 as cv + + +class filter: + def __init__(self, input_file, output_file, img): + self.input_file = input_file + self.output_file = output_file + self.img = img + + +class filter_average(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.float32)/25 + dst = cv.filter2D(self.img, -1, kernel) + plt.xticks([]), plt.yticks([]) + plt.imshow(dst) + print("Average filter") + + +class filter_blur(filter): + def __init__(self, input_file, output_file, img): + super().__init__(input_file, output_file, img) + + def apply(self): + blur = cv.blur(self.img, (5, 5)) + plt.xticks([]), plt.yticks([]) + plt.imshow(blur) + print("Blurring filter") + + +class filter_gaussian(filter): + def __init__(self, input_file, output_file, img): + super().__init__(input_file, output_file, img) + + def apply(self): + blur = cv.GaussianBlur(self.img, (5, 5), 0) + plt.xticks([]), plt.yticks([]) + print("Gaussian filter") diff --git a/src/main.py b/src/main.py new file mode 100644 index 0000000..6b8016e --- /dev/null +++ b/src/main.py @@ -0,0 +1,57 @@ +"""! @file main.py +@brief Main file for the application +@author xlanro00 +""" + +# Import libraries +import argparse as ap +import json +import numpy as np +import matplotlib.pyplot as plt + +# Import custom image filter library +import filters as flt + +parser = ap.ArgumentParser(prog='main.py', + description='loads and stores image') + +parser.add_argument("-i", "--input_file", help="Input file", required=True) +parser.add_argument("-o", "--output_file", help="Output file", required=True) +parser.add_argument('-d', "--dpi", type=int, required=True) +#parser.add_argument( '-s', '--size') +parser.add_argument('filters', type=str, nargs='*') + +args = parser.parse_args() + + +class app: + def __init__(self, input_file, output_file, dpi, filters): + self.input_file = input_file + self.output_file = output_file + self.img = plt.imread(self.input_file) + self.dpi = dpi + self.filters = filters + self.apply_filters() + + def filter_factory(self, filter_name): + if filter_name == "average": + return flt.filter_average + elif filter_name == "blur": + return flt.filter_blur + elif filter_name == "gaussian": + return flt.filter_gaussian + else: + raise ValueError("Invalid filter name") + + def apply_filters(self): + for filter in self.filters: + filter = self.filter_factory(filter) + filter.apply(self) + self.save_image() + + def save_image(self): + # Save processed image + plt.savefig(self.output_file) + + +app = app(args.input_file, args.output_file, args.dpi, args.filters)