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

import cv2 import cv2
import numpy as np import numpy as np
root = tk.Tk()
simGrad = tk.IntVar(root)
class Dyschromasie: class Dyschromasie:
global simGrad
cb_image = np.array([]).astype('float64') cb_image = np.array([]).astype('float64')
sim_image = np.array([]).astype('uint8') 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.rows = rows
self.cols = cols self.cols = cols
self.kanaele = kanaele self.kanaele = kanaele
self.img_mat = img_mat self.img_mat = img_mat
self.sim_faktor = sim_faktor
T = np.array([[0.31399022, 0.63951294, 0.04649755], T = np.array([[0.31399022, 0.63951294, 0.04649755],
[0.15537241, 0.75789446, 0.08670142], [0.15537241, 0.75789446, 0.08670142],
class Protanopie(Dyschromasie): class Protanopie(Dyschromasie):
sim_mat = np.array([[0, 1.05118294, -0.05116099],
[0, 1, 0],
[0, 0, 1]])
def Simulate(self): 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 # Gammakorrektur durchfuehren
self.cb_image = np.copy(self.img_mat).astype('float64') self.cb_image = np.copy(self.img_mat).astype('float64')
for i in range(self.rows): for i in range(self.rows):
for i in range(self.rows): for i in range(self.rows):
for j in range(self.cols): for j in range(self.cols):
self.cb_image[i, j] = np.flipud( 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 = np.copy(self.cb_image)
self.sim_image = self.sim_image.astype('uint8') self.sim_image = self.sim_image.astype('uint8')
for x in range(3): for x in range(3):
self.sim_image[i, j, x] = self.reverseGammaCorrection(self.cb_image[i, j, x]) 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 return self.sim_image
class Deuteranopie(Dyschromasie): class Deuteranopie(Dyschromasie):
sim_mat = np.array([[1, 0, 0],
[0.9513092, 0, 0.04866992],
[0, 0, 1]])
def Simulate(self): 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 # Gammakorrektur durchfuehren
self.cb_image = np.copy(self.img_mat).astype('float64') self.cb_image = np.copy(self.img_mat).astype('float64')
for i in range(self.rows): for i in range(self.rows):
for i in range(self.rows): for i in range(self.rows):
for j in range(self.cols): for j in range(self.cols):
self.cb_image[i, j] = np.flipud( 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 = np.copy(self.cb_image)
self.sim_image = self.sim_image.astype('uint8') self.sim_image = self.sim_image.astype('uint8')
for x in range(3): for x in range(3):
self.sim_image[i, j, x] = self.reverseGammaCorrection(self.cb_image[i, j, x]) 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 return self.sim_image
class Tritanopie(Dyschromasie): class Tritanopie(Dyschromasie):
sim_mat = np.array([[1, 0, 0],
[0, 1, 0],
[-0.86744736, 1.86727089, 0]])
def Simulate(self): 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 # Gammakorrektur durchfuehren
self.cb_image = np.copy(self.img_mat).astype('float64') self.cb_image = np.copy(self.img_mat).astype('float64')
for i in range(self.rows): for i in range(self.rows):
for i in range(self.rows): for i in range(self.rows):
for j in range(self.cols): for j in range(self.cols):
self.cb_image[i, j] = np.flipud( 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 = np.copy(self.cb_image)
self.sim_image = self.sim_image.astype('uint8') self.sim_image = self.sim_image.astype('uint8')
for x in range(3): for x in range(3):
self.sim_image[i, j, x] = self.reverseGammaCorrection(self.cb_image[i, j, x]) 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 return self.sim_image
class AutoScrollbar(tk.Scrollbar): class AutoScrollbar(tk.Scrollbar):
self.canvas.config(height = self.frame.winfo_reqheight()) self.canvas.config(height = self.frame.winfo_reqheight())
root = tk.Tk()
root.title("Projekt Dyschromasie") root.title("Projekt Dyschromasie")
SB = ScrollFrame(root) SB = ScrollFrame(root)
sim_pro = tk.IntVar(root) sim_pro = tk.IntVar(root)
sim_deut = tk.IntVar(root) sim_deut = tk.IntVar(root)
sim_tri = 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 = 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 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 = 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) display_array_deut = cv2.cvtColor(np.copy(d.Simulate()), cv2.COLOR_BGR2RGB)
T = tk.Text(SB.frame, height=1, width=15) T = tk.Text(SB.frame, height=1, width=15)
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 = 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) display_array_tri = cv2.cvtColor(np.copy(t.Simulate()), cv2.COLOR_BGR2RGB)
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 = 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) display_array_pro = cv2.cvtColor(np.copy(p.Simulate()), cv2.COLOR_BGR2RGB)
T = tk.Text(SB.frame, height=1, width=15) T = tk.Text(SB.frame, height=1, width=15)

Loading…
Cancel
Save