2020-06-26 09:58:43 +02:00
|
|
|
|
import cv2 # OpenCV fuer Bildbearbeitung
|
|
|
|
|
import tkinter # Zum Erstellen von GUIs
|
|
|
|
|
import numpy as np # Numpy Import
|
2020-06-22 11:46:32 +02:00
|
|
|
|
import sys
|
2020-06-09 16:16:37 +02:00
|
|
|
|
|
2020-06-26 09:58:43 +02:00
|
|
|
|
# Einlesen des Bildes
|
2020-06-22 11:46:32 +02:00
|
|
|
|
script_dir = sys.path[0]
|
|
|
|
|
path = script_dir[:-4] + "Beispielbilder\lena.jpg"
|
2020-06-26 09:58:43 +02:00
|
|
|
|
image = cv2.imread(path) # Einlesen des Bildes (noch hardcodiert, sollte dann in GUI gehen)
|
|
|
|
|
|
|
|
|
|
rows = image.shape[0] # Auslesen der Zeilenanzahl
|
|
|
|
|
cols = image.shape[1] # Auslesen der Spaltenanzahl
|
|
|
|
|
kanaele = image.shape[2] # Auslesen der Kanaele (3 fuer RGB, 1 fuer Graubild)
|
|
|
|
|
|
2020-06-26 12:45:14 +02:00
|
|
|
|
|
2020-06-26 09:58:43 +02:00
|
|
|
|
def gammaCorrection(v):
|
2020-06-26 12:15:48 +02:00
|
|
|
|
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)
|
2020-06-26 09:58:43 +02:00
|
|
|
|
else:
|
|
|
|
|
print("Ungültiger Wert!!")
|
|
|
|
|
return 1
|
|
|
|
|
|
2020-06-27 10:40:18 +02:00
|
|
|
|
|
2020-06-26 09:58:43 +02:00
|
|
|
|
def reverseGammaCorrection(v_reverse):
|
2020-06-26 12:15:48 +02:00
|
|
|
|
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))
|
2020-06-26 09:58:43 +02:00
|
|
|
|
else:
|
|
|
|
|
print("Ungültiger Wert!!!")
|
|
|
|
|
return 1
|
2020-06-09 16:16:37 +02:00
|
|
|
|
|
2020-06-26 12:15:48 +02:00
|
|
|
|
|
2020-06-27 10:40:18 +02:00
|
|
|
|
cb_image = np.copy(image) # Kopie des Bildarrays
|
|
|
|
|
cb_image = cb_image.astype('float64') # Casting des Arrays auf Float
|
2020-06-26 12:15:48 +02:00
|
|
|
|
|
2020-06-27 10:40:18 +02:00
|
|
|
|
# Korrektur des Gamma Faktors für alle Bildelemente
|
2020-06-26 12:15:48 +02:00
|
|
|
|
for i in range(rows):
|
|
|
|
|
for j in range(cols):
|
|
|
|
|
for x in range(3):
|
2020-06-26 12:45:14 +02:00
|
|
|
|
cb_image[i, j, x] = gammaCorrection(float(image[i, j, x]))
|
2020-06-26 12:15:48 +02:00
|
|
|
|
|
2020-06-22 12:22:51 +02:00
|
|
|
|
'''
|
2020-06-26 11:01:46 +02:00
|
|
|
|
0.31399022 0.63951294 0.04649755 Transformationsmatrix zum Konvertieren vom linearen RGB zum LMS Farbraum
|
|
|
|
|
T = 0.15537241 0.75789446 0.08670142 Multiplikation aus Brucelindbloom und Hunt-Pointer-Estevez Matrixen
|
|
|
|
|
0.01775239 0.10944209 0.87256922 T*RGB_Farbverktor = LMS_Farbvektor
|
2020-06-22 12:22:51 +02:00
|
|
|
|
'''
|
|
|
|
|
|
2020-06-26 12:15:48 +02:00
|
|
|
|
T = np.array([[0.31399022, 0.63951294, 0.04649755],
|
|
|
|
|
[0.15537241, 0.75789446, 0.08670142],
|
|
|
|
|
[0.01775239, 0.10944209, 0.87256922]])
|
2020-06-22 12:22:51 +02:00
|
|
|
|
|
|
|
|
|
'''
|
2020-06-26 11:01:46 +02:00
|
|
|
|
5.47221206 −4.6419601 0.16963708 Rücktransformationsmatrix (Inverse von T)
|
|
|
|
|
T_reversed = -1.1252419 2.29317094 −0.1678952 T_reversed Ü LMS_Farbvektor = RBG_Farbvektor
|
|
|
|
|
0.02980165 −0.19318073 1.16364789
|
2020-06-22 12:22:51 +02:00
|
|
|
|
'''
|
|
|
|
|
|
2020-06-26 12:15:48 +02:00
|
|
|
|
T_reversed = np.array([[5.47221206, -4.6419601, 0.16963708],
|
|
|
|
|
[-1.1252419, 2.29317094, -0.1678952],
|
|
|
|
|
[0.02980165, -0.19318073, 1.16364789]])
|
2020-06-22 12:22:51 +02:00
|
|
|
|
|
2020-06-27 10:40:18 +02:00
|
|
|
|
# Simulationsmatrizen fuer Protanop
|
|
|
|
|
|
|
|
|
|
S_b = np.array([[0, 1.05118294, -0.05116099], #Simulationsmatrix fuer Protanopie
|
|
|
|
|
[0, 1, 0],
|
|
|
|
|
[0, 0, 1]])
|
|
|
|
|
|
|
|
|
|
S_d = np.array([[1, 0, 0], #Simulationsmatrix fuer Deuteranopie
|
|
|
|
|
[0.9513092, 0, 0.04866992],
|
|
|
|
|
[0, 0, 1]])
|
|
|
|
|
|
|
|
|
|
S_t = np.array([[1, 0, 0], #Simulationsmatrix fuer Tritanopie
|
|
|
|
|
[0, 1, 0],
|
|
|
|
|
[-0.86744736, 1.86727089, 0]])
|
|
|
|
|
|
|
|
|
|
|
2020-06-27 10:54:20 +02:00
|
|
|
|
#Multiplikation der einzelnen Pixel
|
|
|
|
|
for i in range(rows):
|
|
|
|
|
for j in range(cols):
|
|
|
|
|
cb_image[i, j] = T_reversed.dot(S_b.dot(T.dot(cb_image[i, j]))) #T^-1*S*T*RBG_values
|
2020-06-26 12:59:09 +02:00
|
|
|
|
|
2020-06-27 10:54:20 +02:00
|
|
|
|
sim_image = np.copy(cb_image)
|
|
|
|
|
sim_image = sim_image.astype('uint8')
|
|
|
|
|
|
|
|
|
|
#Rücktransformation der Gammawerte
|
|
|
|
|
for i in range(rows):
|
|
|
|
|
for j in range(cols):
|
|
|
|
|
for x in range(3):
|
|
|
|
|
sim_image[i, j, x] = int(reverseGammaCorrection(cb_image[i, j, x]))
|
2020-06-17 10:47:09 +02:00
|
|
|
|
|
|
|
|
|
|
2020-06-26 09:58:43 +02:00
|
|
|
|
cv2.namedWindow("Display") # Displaywindow erstellen
|
2020-06-27 10:54:20 +02:00
|
|
|
|
cv2.imshow("Display", sim_image) # Bild zeigen
|
2020-06-26 09:58:43 +02:00
|
|
|
|
cv2.waitKey(0) # Fenster offen halten
|