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 index 51c5059..27744c9 100644 Binary files a/Code/__pycache__/Farbaenderung.cpython-38.pyc and b/Code/__pycache__/Farbaenderung.cpython-38.pyc differ