Browse Source

Einfügen eines Dalt-Buttons in die GUI

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.
master
Max Sponsel 4 years ago
parent
commit
137ca981f2

+ 20
- 9
Code/Dyschromasie-Applikation.py View File

sim_tri = tk.IntVar(root) sim_tri = tk.IntVar(root)
simulationsGradient = tk.Scale(SB.frame, from_=0, to_=100, variable=simGrad, orient='horizontal') 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(): def browse():
# Auswahl des FilePaths # Auswahl des FilePaths
try: 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) im = Image.open(path)
except: except:
tk.messagebox.showerror(title='Datenfehler', message='Kein Bild gefunden/ausgewählt') tk.messagebox.showerror(title='Datenfehler', message='Kein Bild gefunden/ausgewählt')
global simulateButton global simulateButton
if len(path) > 0: if len(path) > 0:
simulateButton.config(state='active') simulateButton.config(state='active')
daltonButton.config(state='active')
# Anzeigen des Bildes # Anzeigen des Bildes
tkimage = ImageTk.PhotoImage(im) tkimage = ImageTk.PhotoImage(im)
def simulate(): def simulate():
global img, rows, cols, kanaele, sim_pro, sim_deut, sim_tri global img, rows, cols, kanaele, sim_pro, sim_deut, sim_tri
if sim_deut.get(): 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') display_array_deut = np.copy(d.Simulate()).astype('uint8')
T = tk.Text(SB.frame, height=1, width=15) T = tk.Text(SB.frame, height=1, width=15)
T.grid(columnspan=5) 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) T.insert('current', print_string)
conv_SimulationPic_deut = ImageTk.PhotoImage(image=PIL.Image.fromarray(display_array_deut)) conv_SimulationPic_deut = ImageTk.PhotoImage(image=PIL.Image.fromarray(display_array_deut))
sim_pic_deut.Image = conv_SimulationPic_deut sim_pic_deut.Image = conv_SimulationPic_deut
sim_pic_deut.grid(columnspan=5) sim_pic_deut.grid(columnspan=5)
elif sim_tri.get(): 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') display_array_tri = np.copy(t.Simulate()).astype('uint8')
T = tk.Text(SB.frame, height=1, width=15) T = tk.Text(SB.frame, height=1, width=15)
sim_pic_tri.Image = conv_SimulationPic_tri sim_pic_tri.Image = conv_SimulationPic_tri
sim_pic_tri.grid(columnspan=5) sim_pic_tri.grid(columnspan=5)
elif sim_pro.get(): 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') display_array_pro = np.copy(p.Simulate()).astype('uint8')
T = tk.Text(SB.frame, height=1, width=15) T = tk.Text(SB.frame, height=1, width=15)
sim_pic_pro.grid(columnspan=5) 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 = 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') 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_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_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) checkButton_t = tk.Checkbutton(SB.frame, text="Tritanop", variable=sim_tri, onvalue=1, offvalue=0, height=5, width=20)

+ 23
- 21
Code/Farbaenderung.py View File

def applyGammaCorrection(v_reverse): def applyGammaCorrection(v_reverse):
if abs(v_reverse) <= 0.0031308: if abs(v_reverse) <= 0.0031308:
return round(255 * (12.92 * abs(v_reverse))) 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: 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) return 255 - (round(255 * (1.055 * abs(v_reverse) ** 0.41666 - 0.055)) - 255)
else: else:
class Dyschromasie: class Dyschromasie:
cb_image = np.array([]).astype('float64') 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'): def __init__(self, img_mat=np.array([]), rows=0, cols=0, kanaele=0, sim_faktor=0, sim_kind='d'):
self.rows = rows self.rows = rows
[0.02980165, -0.19318073, 1.16364789]]) [0.02980165, -0.19318073, 1.16364789]])
def Simulate(self): def Simulate(self):
removeGammaCorrectionLUT = createGammaLookup() removeGammaCorrectionLUT = createGammaLookup()
if self.sim_kind == 'p': if self.sim_kind == 'p':
self.cb_image[i, j] = rechen_Mat.dot(self.cb_image[i, j]) self.cb_image[i, j] = rechen_Mat.dot(self.cb_image[i, j])
self.sim_image = np.copy(self.cb_image) 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 # Rücktransformation der Gammawerte
for i in range(self.rows): for i in range(self.rows):
for j in range(self.cols): for j in range(self.cols):
for x in range(3): for x in range(3):
self.sim_image[i, j, x] = applyGammaCorrection(self.cb_image[i, j, x]) 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): def daltonize(self):
for i in range(self.rows): for i in range(self.rows):
for j in range(self.cols): 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 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') result = dtpn.astype('uint8')
return dalt.Simulate() 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)
dalt = Dyschromasie(image, rows, cols, kanaele, 1, 'p')
cv2.imshow('Dalt_Img', cv2.cvtColor(dalt.daltonize(), cv2.COLOR_RGB2BGR))
cv2.waitKey(0)
# main()

BIN
Code/__pycache__/Farbaenderung.cpython-38.pyc View File


Loading…
Cancel
Save