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.
This commit is contained in:
parent
8498500c68
commit
137ca981f2
@ -23,18 +23,20 @@ sim_deut = tk.IntVar(root)
|
|||||||
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)
|
||||||
@ -52,12 +54,12 @@ def browse():
|
|||||||
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))
|
||||||
@ -65,7 +67,7 @@ def simulate():
|
|||||||
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)
|
||||||
@ -78,7 +80,7 @@ def simulate():
|
|||||||
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)
|
||||||
@ -92,13 +94,22 @@ def simulate():
|
|||||||
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')
|
def daltonize():
|
||||||
btn.grid(column=0, row=0, columnspan=2)
|
#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)
|
||||||
|
@ -21,7 +21,7 @@ def removeGammaCorrection(v):
|
|||||||
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:
|
||||||
@ -30,7 +30,7 @@ def applyGammaCorrection(v_reverse):
|
|||||||
|
|
||||||
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
|
||||||
@ -49,7 +49,6 @@ class Dyschromasie:
|
|||||||
[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':
|
||||||
@ -78,14 +77,14 @@ class Dyschromasie:
|
|||||||
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):
|
||||||
|
|
||||||
@ -109,17 +108,17 @@ class Dyschromasie:
|
|||||||
|
|
||||||
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):
|
||||||
dtpn[i, j, x] = abs(int(ERR[i, j, x]) + int(image[i, j, x]))
|
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):
|
for j in range(cols):
|
||||||
dtpn[i, j, 0] = max(0, dtpn[i, j, 0])
|
dtpn[i, j, 0] = max(0, dtpn[i, j, 0])
|
||||||
dtpn[i, j, 0] = min(255, 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] = max(0, dtpn[i, j, 1])
|
||||||
dtpn[i, j, 1] = min(255, 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] = max(0, dtpn[i, j, 2])
|
||||||
dtpn[i, j, 2] = min(255, dtpn[i, j, 2])
|
dtpn[i, j, 2] = min(255, dtpn[i, j, 2])
|
||||||
|
|
||||||
result = dtpn.astype('uint8')
|
result = dtpn.astype('uint8')
|
||||||
|
|
||||||
@ -127,12 +126,15 @@ class Dyschromasie:
|
|||||||
return dalt.Simulate()
|
return dalt.Simulate()
|
||||||
|
|
||||||
|
|
||||||
script_dir = sys.path[0]
|
def main():
|
||||||
path = script_dir[:-4] + r'Beispielbilder\rot-gruen-schwaeche-test-bild.jpg'
|
script_dir = sys.path[0]
|
||||||
image = cv2.cvtColor(cv2.imread(path), cv2.COLOR_BGR2RGB)
|
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')
|
dalt = Dyschromasie(image, rows, cols, kanaele, 1, 'p')
|
||||||
cv2.imshow('Dalt_Img', cv2.cvtColor(dalt.daltonize(), cv2.COLOR_RGB2BGR))
|
cv2.imshow('Dalt_Img', cv2.cvtColor(dalt.daltonize(), cv2.COLOR_RGB2BGR))
|
||||||
cv2.waitKey(0)
|
cv2.waitKey(0)
|
||||||
|
|
||||||
|
# main()
|
||||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user