|
|
@@ -4,6 +4,7 @@ import tkinter as tk |
|
|
|
from tkinter import filedialog, messagebox
|
|
|
|
import cv2
|
|
|
|
import numpy as np
|
|
|
|
from Farbaenderung import gammaCorrection, reverseGammaCorrection
|
|
|
|
|
|
|
|
root = tk.Tk()
|
|
|
|
simGrad = tk.IntVar(root)
|
|
|
@@ -12,12 +13,13 @@ class Dyschromasie: |
|
|
|
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,sim_faktor=0):
|
|
|
|
def __init__(self, img_mat=np.array([]), rows=0, cols=0, kanaele=0,sim_faktor=0, sim_kind='d'):
|
|
|
|
self.rows = rows
|
|
|
|
self.cols = cols
|
|
|
|
self.kanaele = kanaele
|
|
|
|
self.img_mat = img_mat
|
|
|
|
self.sim_faktor = sim_faktor
|
|
|
|
self.sim_kind = sim_kind
|
|
|
|
|
|
|
|
T = np.array([[0.31399022, 0.63951294, 0.04649755],
|
|
|
|
[0.15537241, 0.75789446, 0.08670142],
|
|
|
@@ -27,94 +29,27 @@ class Dyschromasie: |
|
|
|
[-1.1252419, 2.29317094, -0.1678952],
|
|
|
|
[0.02980165, -0.19318073, 1.16364789]])
|
|
|
|
|
|
|
|
def gammaCorrection(self, v):
|
|
|
|
if v <= 0.04045 * 255:
|
|
|
|
return float(((v / 255) / 12.92))
|
|
|
|
elif v > 0.04045 * 255:
|
|
|
|
return float((((v / 255) + 0.055) / 1.055) ** 2.4)
|
|
|
|
|
|
|
|
def reverseGammaCorrection(self, v_reverse):
|
|
|
|
if v_reverse <= 0.0031308:
|
|
|
|
return int(255 * (12.92 * v_reverse))
|
|
|
|
elif v_reverse > 0.0031308:
|
|
|
|
return int(255 * (1.055 * v_reverse ** 0.41666 - 0.055))
|
|
|
|
|
|
|
|
|
|
|
|
class Protanopie(Dyschromasie):
|
|
|
|
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):
|
|
|
|
for j in range(self.cols):
|
|
|
|
for x in range(3):
|
|
|
|
self.cb_image[i, j, x] = self.gammaCorrection(self.img_mat[i, j, x])
|
|
|
|
|
|
|
|
# Einzelne Pixelwertberechnung
|
|
|
|
for i in range(self.rows):
|
|
|
|
for j in range(self.cols):
|
|
|
|
self.cb_image[i, j] = self.T_reversed.dot(sim_mat).dot(self.T).dot(self.cb_image[i, j])
|
|
|
|
|
|
|
|
self.sim_image = np.copy(self.cb_image)
|
|
|
|
self.sim_image = self.sim_image.astype('uint8')
|
|
|
|
# Rücktransformation der Gammawerte
|
|
|
|
for i in range(self.rows):
|
|
|
|
for j in range(self.cols):
|
|
|
|
for x in range(3):
|
|
|
|
self.sim_image[i, j, x] = self.reverseGammaCorrection(self.cb_image[i, j, x])
|
|
|
|
|
|
|
|
return self.sim_image
|
|
|
|
|
|
|
|
|
|
|
|
class Deuteranopie(Dyschromasie):
|
|
|
|
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]])
|
|
|
|
if self.sim_kind == 'p':
|
|
|
|
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':
|
|
|
|
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:
|
|
|
|
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):
|
|
|
|
for j in range(self.cols):
|
|
|
|
for x in range(3):
|
|
|
|
self.cb_image[i, j, x] = self.gammaCorrection(self.img_mat[i, j, x])
|
|
|
|
|
|
|
|
# Einzelne Pixelwertberechnung
|
|
|
|
for i in range(self.rows):
|
|
|
|
for j in range(self.cols):
|
|
|
|
self.cb_image[i, j] = self.T_reversed.dot(sim_mat).dot(self.T).dot(self.cb_image[i, j])
|
|
|
|
|
|
|
|
self.sim_image = np.copy(self.cb_image)
|
|
|
|
self.sim_image = self.sim_image.astype('uint8')
|
|
|
|
|
|
|
|
# Rücktransformation der Gammawerte
|
|
|
|
for i in range(self.rows):
|
|
|
|
for j in range(self.cols):
|
|
|
|
for x in range(3):
|
|
|
|
self.sim_image[i, j, x] = self.reverseGammaCorrection(self.cb_image[i, j, x])
|
|
|
|
|
|
|
|
return self.sim_image
|
|
|
|
|
|
|
|
|
|
|
|
class Tritanopie(Dyschromasie):
|
|
|
|
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):
|
|
|
|
for j in range(self.cols):
|
|
|
|
for x in range(3):
|
|
|
|
self.cb_image[i, j, x] = self.gammaCorrection(self.img_mat[i, j, x])
|
|
|
|
self.cb_image[i, j, x] = gammaCorrection(self.img_mat[i, j, x])
|
|
|
|
|
|
|
|
# Einzelne Pixelwertberechnung
|
|
|
|
for i in range(self.rows):
|
|
|
@@ -123,12 +58,11 @@ class Tritanopie(Dyschromasie): |
|
|
|
|
|
|
|
self.sim_image = np.copy(self.cb_image)
|
|
|
|
self.sim_image = self.sim_image.astype('uint8')
|
|
|
|
|
|
|
|
# Rücktransformation der Gammawerte
|
|
|
|
for i in range(self.rows):
|
|
|
|
for j in range(self.cols):
|
|
|
|
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] = reverseGammaCorrection(self.cb_image[i, j, x])
|
|
|
|
|
|
|
|
return self.sim_image
|
|
|
|
|
|
|
@@ -233,8 +167,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, simGrad.get()/100)
|
|
|
|
display_array_deut = d.Simulate()
|
|
|
|
d = Dyschromasie(img, rows, cols, kanaele, simGrad.get()/100, 'd')
|
|
|
|
display_array_deut = np.copy(d.Simulate()).astype('uint8')
|
|
|
|
|
|
|
|
T = tk.Text(SB.frame, height=1, width=15)
|
|
|
|
T.grid(columnspan=5)
|
|
|
@@ -246,8 +180,8 @@ 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, simGrad.get()/100)
|
|
|
|
display_array_tri = t.Simulate()
|
|
|
|
t = Dyschromasie(img, rows, cols, kanaele, simGrad.get()/100, 't')
|
|
|
|
display_array_tri = np.copy(t.Simulate()).astype('uint8')
|
|
|
|
|
|
|
|
T = tk.Text(SB.frame, height=1, width=15)
|
|
|
|
T.grid(columnspan=5)
|
|
|
@@ -259,8 +193,8 @@ 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, simGrad.get()/100)
|
|
|
|
display_array_pro = p.Simulate()
|
|
|
|
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)
|