From 137ca981f2cae72ec417cc967f13a700f38b9a3a Mon Sep 17 00:00:00 2001 From: Max Sponsel Date: Fri, 18 Sep 2020 11:40:40 +0200 Subject: [PATCH] =?UTF-8?q?Einf=C3=BCgen=20eines=20Dalt-Buttons=20in=20die?= =?UTF-8?q?=20GUI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Zum Aufrufen des Algorithmus in der GUI muss ein Button Objekt der tkinter Klasse erstellt werden. Dieses wird erst nach einem erfolgreich ausgewählten Bild aktiv! Als nächstes steht die Implementation der daltonize-Funktion an, die durch command='daltonize' ausgeführt wird. --- Code/Dyschromasie-Applikation.py | 29 ++++++++---- Code/Farbaenderung.py | 44 +++++++++--------- Code/__pycache__/Farbaenderung.cpython-38.pyc | Bin 3068 -> 4544 bytes 3 files changed, 43 insertions(+), 30 deletions(-) diff --git a/Code/Dyschromasie-Applikation.py b/Code/Dyschromasie-Applikation.py index 3a1c5b0..6747e94 100644 --- a/Code/Dyschromasie-Applikation.py +++ b/Code/Dyschromasie-Applikation.py @@ -23,18 +23,20 @@ sim_deut = tk.IntVar(root) sim_tri = tk.IntVar(root) simulationsGradient = tk.Scale(SB.frame, from_=0, to_=100, variable=simGrad, orient='horizontal') -simulationsGradient.grid(column= 0, row = 1, columnspan=10) +simulationsGradient.grid(column=0, row=1, columnspan=10) + def browse(): # Auswahl des FilePaths try: - path = tk.filedialog.askopenfilename(filetypes=[("Image File", '.jpg'),("Image File", '.png')]) + path = tk.filedialog.askopenfilename(filetypes=[("Image File", '.jpg'), ("Image File", '.png')]) im = Image.open(path) except: tk.messagebox.showerror(title='Datenfehler', message='Kein Bild gefunden/ausgewählt') global simulateButton if len(path) > 0: simulateButton.config(state='active') + daltonButton.config(state='active') # Anzeigen des Bildes tkimage = ImageTk.PhotoImage(im) @@ -52,12 +54,12 @@ def browse(): def simulate(): global img, rows, cols, kanaele, sim_pro, sim_deut, sim_tri if sim_deut.get(): - d = Dyschromasie(img, rows, cols, kanaele, simGrad.get()/100, 'd') + d = Dyschromasie(img, rows, cols, kanaele, simGrad.get() / 100, 'd') display_array_deut = np.copy(d.Simulate()).astype('uint8') T = tk.Text(SB.frame, height=1, width=15) T.grid(columnspan=5) - print_string = "Deutranop(" + str(round(d.sim_faktor*100)) + "%)" + print_string = "Deutranop(" + str(round(d.sim_faktor * 100)) + "%)" T.insert('current', print_string) conv_SimulationPic_deut = ImageTk.PhotoImage(image=PIL.Image.fromarray(display_array_deut)) @@ -65,7 +67,7 @@ def simulate(): sim_pic_deut.Image = conv_SimulationPic_deut sim_pic_deut.grid(columnspan=5) elif sim_tri.get(): - t = Dyschromasie(img, rows, cols, kanaele, simGrad.get()/100, 't') + t = Dyschromasie(img, rows, cols, kanaele, simGrad.get() / 100, 't') display_array_tri = np.copy(t.Simulate()).astype('uint8') T = tk.Text(SB.frame, height=1, width=15) @@ -78,7 +80,7 @@ def simulate(): sim_pic_tri.Image = conv_SimulationPic_tri sim_pic_tri.grid(columnspan=5) elif sim_pro.get(): - p = Dyschromasie(img, rows, cols, kanaele, simGrad.get()/100, 'p') + p = Dyschromasie(img, rows, cols, kanaele, simGrad.get() / 100, 'p') display_array_pro = np.copy(p.Simulate()).astype('uint8') T = tk.Text(SB.frame, height=1, width=15) @@ -92,13 +94,22 @@ def simulate(): sim_pic_pro.grid(columnspan=5) -btn = tk.Button(SB.frame, text="Browse", width=25, command=browse, bg='light blue') -btn.grid(column=0, row=0, columnspan=2) +def daltonize(): + #ToDo + print("working") + + +browseButton = tk.Button(SB.frame, text="Browse", width=25, command=browse, bg='light blue') +browseButton.grid(column=0, row=0, columnspan=1) simulateButton = tk.Button(SB.frame, text="Simulate", width=25, command=simulate, bg='light blue') -simulateButton.grid(column=1, row=0, columnspan=2) +simulateButton.grid(column=1, row=0, columnspan=1) simulateButton.config(state='disabled') +daltonButton = tk.Button(SB.frame, text="Daltonize", width=25, command=daltonize, bg='light blue') +daltonButton.grid(column=2, row=0, columnspan=1) +daltonButton.config(state='disabled') + checkButton_p = tk.Checkbutton(SB.frame, text="Protanop", variable=sim_pro, onvalue=1, offvalue=0, height=5, width=20) checkButton_d = tk.Checkbutton(SB.frame, text="Deutanop", variable=sim_deut, onvalue=1, offvalue=0, height=5, width=20) checkButton_t = tk.Checkbutton(SB.frame, text="Tritanop", variable=sim_tri, onvalue=1, offvalue=0, height=5, width=20) diff --git a/Code/Farbaenderung.py b/Code/Farbaenderung.py index 09fd202..3643b23 100644 --- a/Code/Farbaenderung.py +++ b/Code/Farbaenderung.py @@ -21,7 +21,7 @@ def removeGammaCorrection(v): def applyGammaCorrection(v_reverse): if abs(v_reverse) <= 0.0031308: return round(255 * (12.92 * abs(v_reverse))) - elif abs(v_reverse) > 0.0031308: + else: if (round(255 * (1.055 * abs(v_reverse) ** 0.41666 - 0.055))) > 255: return 255 - (round(255 * (1.055 * abs(v_reverse) ** 0.41666 - 0.055)) - 255) else: @@ -30,7 +30,7 @@ def applyGammaCorrection(v_reverse): class Dyschromasie: cb_image = np.array([]).astype('float64') - sim_image = np.array([]).astype('uint8') + sim_image = np.array([]).astype('int64') def __init__(self, img_mat=np.array([]), rows=0, cols=0, kanaele=0, sim_faktor=0, sim_kind='d'): self.rows = rows @@ -49,7 +49,6 @@ class Dyschromasie: [0.02980165, -0.19318073, 1.16364789]]) def Simulate(self): - removeGammaCorrectionLUT = createGammaLookup() if self.sim_kind == 'p': @@ -78,14 +77,14 @@ class Dyschromasie: self.cb_image[i, j] = rechen_Mat.dot(self.cb_image[i, j]) self.sim_image = np.copy(self.cb_image) - self.sim_image = self.sim_image.astype('uint8') + self.sim_image = self.sim_image.astype('int64') # Rücktransformation der Gammawerte for i in range(self.rows): for j in range(self.cols): for x in range(3): self.sim_image[i, j, x] = applyGammaCorrection(self.cb_image[i, j, x]) - return self.sim_image + return self.sim_image.astype('uint8') def daltonize(self): @@ -109,17 +108,17 @@ class Dyschromasie: for i in range(self.rows): for j in range(self.cols): - for x in range(3): - dtpn[i, j, x] = abs(int(ERR[i, j, x]) + int(image[i, j, x])) + for x in range(3): + dtpn[i, j, x] = abs(int(ERR[i, j, x]) + int(image[i, j, x])) for i in range(rows): - for j in range(cols): - dtpn[i, j, 0] = max(0, dtpn[i, j, 0]) - dtpn[i, j, 0] = min(255, dtpn[i, j, 0]) - dtpn[i, j, 1] = max(0, dtpn[i, j, 1]) - dtpn[i, j, 1] = min(255, dtpn[i, j, 1]) - dtpn[i, j, 2] = max(0, dtpn[i, j, 2]) - dtpn[i, j, 2] = min(255, dtpn[i, j, 2]) + for j in range(cols): + dtpn[i, j, 0] = max(0, dtpn[i, j, 0]) + dtpn[i, j, 0] = min(255, dtpn[i, j, 0]) + dtpn[i, j, 1] = max(0, dtpn[i, j, 1]) + dtpn[i, j, 1] = min(255, dtpn[i, j, 1]) + dtpn[i, j, 2] = max(0, dtpn[i, j, 2]) + dtpn[i, j, 2] = min(255, dtpn[i, j, 2]) result = dtpn.astype('uint8') @@ -127,12 +126,15 @@ class Dyschromasie: return dalt.Simulate() -script_dir = sys.path[0] -path = script_dir[:-4] + r'Beispielbilder\rot-gruen-schwaeche-test-bild.jpg' -image = cv2.cvtColor(cv2.imread(path), cv2.COLOR_BGR2RGB) +def main(): + script_dir = sys.path[0] + path = script_dir[:-4] + r'Beispielbilder\rot-gruen-schwaeche-test-bild.jpg' + image = cv2.cvtColor(cv2.imread(path), cv2.COLOR_BGR2RGB) -rows, cols, kanaele = image.shape + rows, cols, kanaele = image.shape -dalt = Dyschromasie(image, rows, cols, kanaele, 1, 'p') -cv2.imshow('Dalt_Img', cv2.cvtColor(dalt.daltonize(), cv2.COLOR_RGB2BGR)) -cv2.waitKey(0) \ No newline at end of file + dalt = Dyschromasie(image, rows, cols, kanaele, 1, 'p') + cv2.imshow('Dalt_Img', cv2.cvtColor(dalt.daltonize(), cv2.COLOR_RGB2BGR)) + cv2.waitKey(0) + +# main() diff --git a/Code/__pycache__/Farbaenderung.cpython-38.pyc b/Code/__pycache__/Farbaenderung.cpython-38.pyc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