Dalt Algorithmus und Auslagern des Displays
Der Dalt Algorithmus wird nun von dem Dalt-Button ausgeführt. Gleichzeitig wurde die Funktion showImage geschrieben, um Code zu verschlanken und lediglich die Switchfunktionen simulate und daltonize für die Auswahl der Simulationsart zu nutzen. PS: Mehrere Bilder zum Testen eingefügt
This commit is contained in:
parent
137ca981f2
commit
a206147edf
BIN
Beispielbilder/Ishihara-Plate-Tritanop12.jpg
Normal file
BIN
Beispielbilder/Ishihara-Plate-Tritanop12.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 32 KiB |
BIN
Beispielbilder/Ishihara-Plate-Tritanop42.jpg
Normal file
BIN
Beispielbilder/Ishihara-Plate-Tritanop42.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 149 KiB |
@ -51,52 +51,46 @@ def browse():
|
||||
rows, cols, kanaele = img.shape
|
||||
|
||||
|
||||
def showImage(img, rows, cols, kanaele, sim_faktor, sim_kind, sim_art):
|
||||
color_blindness = Dyschromasie(img, rows, cols, kanaele, sim_faktor, sim_kind)
|
||||
if sim_art == 'Sim':
|
||||
color_blindness_mat = np.copy(color_blindness.Simulate()).astype('uint8')
|
||||
else:
|
||||
color_blindness_mat = np.copy(color_blindness.daltonize()).astype('uint8')
|
||||
|
||||
T = tk.Text(SB.frame, height=1, width=15)
|
||||
T.grid(columnspan=5)
|
||||
print_string = sim_kind + ' ' + str(round(color_blindness.sim_faktor * 100)) + "%)"
|
||||
T.insert('current', print_string)
|
||||
|
||||
conv_SimulationPic = ImageTk.PhotoImage(image=PIL.Image.fromarray(color_blindness_mat))
|
||||
sim_pic = tk.Label(SB.frame, image=conv_SimulationPic)
|
||||
sim_pic.Image = conv_SimulationPic
|
||||
sim_pic.grid(columnspan=5)
|
||||
|
||||
|
||||
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')
|
||||
display_array_deut = np.copy(d.Simulate()).astype('uint8')
|
||||
showImage(img, rows, cols, kanaele, simGrad.get()/100, 'Deuteranop', 'Sim')
|
||||
|
||||
T = tk.Text(SB.frame, height=1, width=15)
|
||||
T.grid(columnspan=5)
|
||||
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))
|
||||
sim_pic_deut = tk.Label(SB.frame, image=conv_SimulationPic_deut)
|
||||
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')
|
||||
display_array_tri = np.copy(t.Simulate()).astype('uint8')
|
||||
showImage(img, rows, cols, kanaele, simGrad.get() / 100, 'Tritanop', 'Sim')
|
||||
|
||||
T = tk.Text(SB.frame, height=1, width=15)
|
||||
T.grid(columnspan=5)
|
||||
print_string = "Tritanop(" + str(round(t.sim_faktor * 100)) + "%)"
|
||||
T.insert('current', print_string)
|
||||
|
||||
conv_SimulationPic_tri = ImageTk.PhotoImage(image=PIL.Image.fromarray(display_array_tri))
|
||||
sim_pic_tri = tk.Label(SB.frame, image=conv_SimulationPic_tri)
|
||||
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')
|
||||
display_array_pro = np.copy(p.Simulate()).astype('uint8')
|
||||
|
||||
T = tk.Text(SB.frame, height=1, width=15)
|
||||
T.grid(columnspan=5)
|
||||
print_string = "Protanop(" + str(round(p.sim_faktor * 100)) + "%)"
|
||||
T.insert('current', print_string)
|
||||
|
||||
conv_SimulationPic_pro = ImageTk.PhotoImage(image=PIL.Image.fromarray(display_array_pro))
|
||||
sim_pic_pro = tk.Label(SB.frame, image=conv_SimulationPic_pro)
|
||||
sim_pic_pro.Image = conv_SimulationPic_pro
|
||||
sim_pic_pro.grid(columnspan=5)
|
||||
showImage(img, rows, cols, kanaele, simGrad.get() / 100, 'Protanop', 'Sim')
|
||||
|
||||
|
||||
def daltonize():
|
||||
#ToDo
|
||||
print("working")
|
||||
global img, rows, cols, kanaele, sim_pro, sim_deut, sim_tri
|
||||
if sim_deut.get():
|
||||
showImage(img, rows, cols, kanaele, simGrad.get()/100, 'Deuteranop', 'Dalt')
|
||||
|
||||
elif sim_tri.get():
|
||||
showImage(img, rows, cols, kanaele, simGrad.get() / 100, 'Tritanop', 'Dalt')
|
||||
|
||||
elif sim_pro.get():
|
||||
showImage(img, rows, cols, kanaele, simGrad.get() / 100, 'Protanop', 'Dalt')
|
||||
|
||||
|
||||
browseButton = tk.Button(SB.frame, text="Browse", width=25, command=browse, bg='light blue')
|
||||
|
@ -32,7 +32,7 @@ class Dyschromasie:
|
||||
cb_image = np.array([]).astype('float64')
|
||||
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='Deuteranop'):
|
||||
self.rows = rows
|
||||
self.cols = cols
|
||||
self.kanaele = kanaele
|
||||
@ -51,15 +51,15 @@ class Dyschromasie:
|
||||
def Simulate(self):
|
||||
removeGammaCorrectionLUT = createGammaLookup()
|
||||
|
||||
if self.sim_kind == 'p':
|
||||
if self.sim_kind == 'Protanop':
|
||||
sim_mat = np.array([[(1 - self.sim_faktor), 1.05118294 * self.sim_faktor, -0.05116099 * self.sim_faktor],
|
||||
[0, 1, 0],
|
||||
[0, 0, 1]])
|
||||
elif self.sim_kind == 'd':
|
||||
elif self.sim_kind == 'Deuteranop':
|
||||
sim_mat = np.array([[1, 0, 0],
|
||||
[0.9513092 * self.sim_faktor, (1 - self.sim_faktor), 0.04866992 * self.sim_faktor],
|
||||
[0, 0, 1]])
|
||||
else:
|
||||
elif self.sim_kind == 'Tritanop':
|
||||
sim_mat = np.array([[1, 0, 0],
|
||||
[0, 1, 0],
|
||||
[-0.86744736 * self.sim_faktor, 1.86727089 * self.sim_faktor, (1 - self.sim_faktor)]])
|
||||
@ -97,22 +97,22 @@ class Dyschromasie:
|
||||
for x in range(3):
|
||||
E[i, j, x] = abs(int(self.img_mat[i, j, x]) - int(simulated_image[i, j, x]))
|
||||
|
||||
ERR = np.zeros_like(image).astype('int32')
|
||||
ERR = np.zeros_like(self.img_mat).astype('int32')
|
||||
|
||||
for i in range(self.rows):
|
||||
for j in range(self.cols):
|
||||
err = E[i, j, :3]
|
||||
ERR[i, j, :3] = np.dot(err2mod, err)
|
||||
|
||||
dtpn = np.copy(image).astype('int32')
|
||||
dtpn = np.copy(self.img_mat).astype('int32')
|
||||
|
||||
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]))
|
||||
dtpn[i, j, x] = abs(int(ERR[i, j, x]) + int(self.img_mat[i, j, x]))
|
||||
|
||||
for i in range(rows):
|
||||
for j in range(cols):
|
||||
for i in range(self.rows):
|
||||
for j in range(self.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])
|
||||
@ -125,16 +125,3 @@ class Dyschromasie:
|
||||
dalt = Dyschromasie(result, self.rows, self.cols, self.kanaele, self.sim_faktor, self.sim_kind)
|
||||
return dalt.Simulate()
|
||||
|
||||
|
||||
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
|
||||
|
||||
dalt = Dyschromasie(image, rows, cols, kanaele, 1, 'p')
|
||||
cv2.imshow('Dalt_Img', cv2.cvtColor(dalt.daltonize(), cv2.COLOR_RGB2BGR))
|
||||
cv2.waitKey(0)
|
||||
|
||||
# main()
|
||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user