Browse Source

Abschwächung der Simulationsstärke

Durch Anpassungen in den Simulationsmatrizen ergeben sich Abschwächungsmuster. Somit können für verschiedene Probanden unterschiedliche Stärken der Sehschwäche simuliert werden.
master
Max Sponsel 4 years ago
parent
commit
a1ebdb827c
1 changed files with 25 additions and 56 deletions
  1. 25
    56
      Code/Dyschromasie-Applikation.py

+ 25
- 56
Code/Dyschromasie-Applikation.py View File

@@ -5,17 +5,19 @@ from tkinter import filedialog, messagebox
import cv2
import numpy as np
root = tk.Tk()
simGrad = tk.IntVar(root)
class Dyschromasie:
global simGrad
cb_image = np.array([]).astype('float64')
sim_image = np.array([]).astype('uint8')
def __init__(self, img_mat=np.array([]), rows=0, cols=0, kanaele=0):
def __init__(self, img_mat=np.array([]), rows=0, cols=0, kanaele=0,sim_faktor=0):
self.rows = rows
self.cols = cols
self.kanaele = kanaele
self.img_mat = img_mat
self.sim_faktor = sim_faktor
T = np.array([[0.31399022, 0.63951294, 0.04649755],
[0.15537241, 0.75789446, 0.08670142],
@@ -39,11 +41,12 @@ class Dyschromasie:
class Protanopie(Dyschromasie):
sim_mat = np.array([[0, 1.05118294, -0.05116099],
[0, 1, 0],
[0, 0, 1]])
def Simulate(self):
sim_mat = np.array([[(1 - self.sim_faktor), 1.05118294 * self.sim_faktor, -0.05116099 * self.sim_faktor],
[0, 1, 0],
[0, 0, 1]])
# Gammakorrektur durchfuehren
self.cb_image = np.copy(self.img_mat).astype('float64')
for i in range(self.rows):
@@ -55,7 +58,7 @@ class Protanopie(Dyschromasie):
for i in range(self.rows):
for j in range(self.cols):
self.cb_image[i, j] = np.flipud(
self.T_reversed.dot(self.sim_mat).dot(self.T).dot(np.flipud(self.cb_image[i, j])))
self.T_reversed.dot(sim_mat).dot(self.T).dot(np.flipud(self.cb_image[i, j])))
self.sim_image = np.copy(self.cb_image)
self.sim_image = self.sim_image.astype('uint8')
@@ -66,25 +69,16 @@ class Protanopie(Dyschromasie):
for x in range(3):
self.sim_image[i, j, x] = self.reverseGammaCorrection(self.cb_image[i, j, x])
# Anpassung fuer den Slider
if(simGrad.get() != 0):
for i in range(rows):
for j in range(cols):
for x in range(3):
if self.sim_image[i, j, x] > img[i, j, x]:
self.sim_image[i, j, x] = img[i, j, x] + abs(self.sim_image[i, j, x] - img[i, j, x])* (simGrad.get()/100)
elif self.sim_image[i, j, x] < img[i, j, x]:
self.sim_image[i, j, x] = self.sim_image[i, j, x] + abs(img[i, j, x] - self.sim_image[i, j, x])* (simGrad.get()/100)
return self.sim_image
class Deuteranopie(Dyschromasie):
sim_mat = np.array([[1, 0, 0],
[0.9513092, 0, 0.04866992],
[0, 0, 1]])
def Simulate(self):
sim_mat = np.array([[1, 0, 0],
[0.9513092 * self.sim_faktor, (1 - self.sim_faktor), 0.04866992 * self.sim_faktor],
[0, 0, 1]])
# Gammakorrektur durchfuehren
self.cb_image = np.copy(self.img_mat).astype('float64')
for i in range(self.rows):
@@ -96,7 +90,7 @@ class Deuteranopie(Dyschromasie):
for i in range(self.rows):
for j in range(self.cols):
self.cb_image[i, j] = np.flipud(
self.T_reversed.dot(self.sim_mat).dot(self.T).dot(np.flipud(self.cb_image[i, j])))
self.T_reversed.dot(sim_mat).dot(self.T).dot(np.flipud(self.cb_image[i, j])))
self.sim_image = np.copy(self.cb_image)
self.sim_image = self.sim_image.astype('uint8')
@@ -107,26 +101,16 @@ class Deuteranopie(Dyschromasie):
for x in range(3):
self.sim_image[i, j, x] = self.reverseGammaCorrection(self.cb_image[i, j, x])
# Anpassung fuer den Slider
if (simGrad.get() != 0):
for i in range(rows):
for j in range(cols):
for x in range(3):
if self.sim_image[i, j, x] > img[i, j, x]:
self.sim_image[i, j, x] = img[i, j, x] + abs(self.sim_image[i, j, x] - img[i, j, x]) * (simGrad.get() / 100)
elif self.sim_image[i, j, x] < img[i, j, x]:
self.sim_image[i, j, x] = self.sim_image[i, j, x] + abs(img[i, j, x] - self.sim_image[i, j, x]) * (simGrad.get() / 100)
return self.sim_image
class Tritanopie(Dyschromasie):
sim_mat = np.array([[1, 0, 0],
[0, 1, 0],
[-0.86744736, 1.86727089, 0]])
def Simulate(self):
sim_mat = np.array([[1, 0, 0],
[0, 1, 0],
[-0.86744736 * self.sim_faktor, 1.86727089 * self.sim_faktor, (1 - self.sim_faktor)]])
# Gammakorrektur durchfuehren
self.cb_image = np.copy(self.img_mat).astype('float64')
for i in range(self.rows):
@@ -138,7 +122,7 @@ class Tritanopie(Dyschromasie):
for i in range(self.rows):
for j in range(self.cols):
self.cb_image[i, j] = np.flipud(
self.T_reversed.dot(self.sim_mat).dot(self.T).dot(np.flipud(self.cb_image[i, j])))
self.T_reversed.dot(sim_mat).dot(self.T).dot(np.flipud(self.cb_image[i, j])))
self.sim_image = np.copy(self.cb_image)
self.sim_image = self.sim_image.astype('uint8')
@@ -149,17 +133,6 @@ class Tritanopie(Dyschromasie):
for x in range(3):
self.sim_image[i, j, x] = self.reverseGammaCorrection(self.cb_image[i, j, x])
# Anpassung fuer den Slider
if (simGrad.get() != 0):
for i in range(rows):
for j in range(cols):
for x in range(3):
if self.sim_image[i, j, x] > img[i, j, x]:
self.sim_image[i, j, x] = img[i, j, x] + abs(self.sim_image[i, j, x] - img[i, j, x]) * (simGrad.get() / 100)
elif self.sim_image[i, j, x] < img[i, j, x]:
self.sim_image[i, j, x] = self.sim_image[i, j, x] + abs(img[i, j, x] - self.sim_image[i, j, x]) * (simGrad.get() / 100)
return self.sim_image
class AutoScrollbar(tk.Scrollbar):
@@ -220,8 +193,6 @@ class ScrollFrame:
self.canvas.config(height = self.frame.winfo_reqheight())
root = tk.Tk()
root.title("Projekt Dyschromasie")
SB = ScrollFrame(root)
@@ -234,7 +205,6 @@ kanaele = 0
sim_pro = tk.IntVar(root)
sim_deut = tk.IntVar(root)
sim_tri = tk.IntVar(root)
simGrad = tk.IntVar(root)
simulationsGradient = tk.Scale(SB.frame, from_=0, to_=100, variable=simGrad, orient='horizontal')
simulationsGradient.grid(column= 0, row = 1, columnspan=10)
@@ -264,9 +234,8 @@ def browse():
def simulate():
global img, rows, cols, kanaele, sim_pro, sim_deut, sim_tri
if sim_deut.get():
d = Deuteranopie(img, rows, cols, kanaele)
d = Deuteranopie(img, rows, cols, kanaele, simGrad.get()/100)
display_array_deut = cv2.cvtColor(np.copy(d.Simulate()), cv2.COLOR_BGR2RGB)
T = tk.Text(SB.frame, height=1, width=15)
@@ -278,7 +247,7 @@ def simulate():
sim_pic_deut.Image = conv_SimulationPic_deut
sim_pic_deut.grid(columnspan=5)
elif sim_tri.get():
t = Tritanopie(img, rows, cols, kanaele)
t = Tritanopie(img, rows, cols, kanaele, simGrad.get()/100)
display_array_tri = cv2.cvtColor(np.copy(t.Simulate()), cv2.COLOR_BGR2RGB)
T = tk.Text(SB.frame, height=1, width=15)
@@ -290,7 +259,7 @@ def simulate():
sim_pic_tri.Image = conv_SimulationPic_tri
sim_pic_tri.grid(columnspan=5)
elif sim_pro.get():
p = Protanopie(img, rows, cols, kanaele)
p = Protanopie(img, rows, cols, kanaele, simGrad.get()/100)
display_array_pro = cv2.cvtColor(np.copy(p.Simulate()), cv2.COLOR_BGR2RGB)
T = tk.Text(SB.frame, height=1, width=15)

Loading…
Cancel
Save