From fc660aea4a9b866caddfe1d58017b0d57b6e2fab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rostislav=20L=C3=A1n?= Date: Mon, 21 Nov 2022 19:42:31 +0100 Subject: [PATCH] Migrated drom github. --- src/__pycache__/filters.cpython-310.pyc | Bin 0 -> 2164 bytes src/filters.py | 48 ++++++++++++++++++++ src/main.py | 57 ++++++++++++++++++++++++ 3 files changed, 105 insertions(+) create mode 100644 src/__pycache__/filters.cpython-310.pyc create mode 100644 src/filters.py create mode 100644 src/main.py diff --git a/src/__pycache__/filters.cpython-310.pyc b/src/__pycache__/filters.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..c49239fd8d6a78e168c75e352919f99a2d06b15f GIT binary patch literal 2164 zcmbtVOK;mo5Z(t#QIz~j-6m~-R%r{gYHQ1Id+4Dk+{9=ug%BV&T?m>>$&4vd-Cenn zpqy+Vf5STJFYUD_pL+1Emv&|;%C7`Hbb+1SnO*MA%=gW*SX&DSw3AOn{Fg(>pQzky zU?T_6)e#6mdPGpcGTLKyVgzlh#2$&5{-fok+Dingj<&GEMreU#+E;rAIQ7lUBcwEq$D{ zqR}Wz<4C7P9vnnteGK;3S(M9SZ!fq6zezVnd9yK44xp=T5DDo~h|R`yPI_E$@We4* z=|PM+s2a}k+h@?#M<8Z&MnW=UAnA;QWP-dT3)*dS6QucQtV4{(G>WlaDLfqx7LIXL zlJzAXDP0sEhy{^#82!SvH?d}hi(XD zjKn11qC)q5(xldMFV7rSv0Z%$qRR7I(x=Fub02e!jOjUVi9>oW@+ze7ZgxnGd}0QMaaIy)de%I8jliL#!y2OHT5uzvq-5hECaH!U>qMn zzrvul>Ga`k2UbaoDXdow??6wUL07+l(BOxln!I9jCfH;0hH8G{%*ZQO@EM)+H%xmM zwE>w^7=0Z3j1rjFXKYSk7C_y=h!M2i?t)!fQapmAFF!`{547p}FJ)Gi<K`+dXWQ{$IG>>pZM89vIi@m}jRK2gS-EXQ=Hj*CBxJCbRx+g$o^kMT|t znJ1ayLg_oO8yAahg2Y#tx(9TVZUeuXbh>>fX?EknlgLE5hGHFsCDd0iGiysI;v~x| zIFR}hVU-q`O_)7^euYd%l5KK{wix=YhG1Zm8z6u}jiob3*;u}pKXMDdz)vM!B9S8H z<<^ZAH9kW-hP;Xqk9{{QkU>}xmK8t31X%$bfVXANN=8@)@C$dv0Dj>CKac@6!B!05 zUHK62+;|F?0X%~WabJE4cH^KE7F*c@T|PnaIf^e(V7)Dv1yp{A1{>3LU)9?yzN>9<=3}Az6R%8SU^wYHz-hxq2FqlTWl39%U38IL}R7WDF5Hk*sCoxkCvWS zN53DQRnhK&XV>ru1|@1s_8vf<;44_15*CS1!F1#KGLQ zci@6{`*>qH@5#kW*5G1Xi>2j0!c!_h=Oh7D$G80k?~X!xbV ze->xPD@W_F;qmFd4avUlw)QO25)ZxM`ifV^|Ec_w{EP`wSga25-6r+vI^V2qHn$u9 E0x1-{*#H0l literal 0 HcmV?d00001 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)