|
|
|
|
|
|
|
|
import cv2 #OpenCV fuer Bildbearbeitung
|
|
|
|
|
|
import tkinter #Zum Erstellen von GUIs
|
|
|
|
|
|
import numpy as np #Numpy Import
|
|
|
|
|
|
|
|
|
import cv2 # OpenCV fuer Bildbearbeitung
|
|
|
|
|
|
import tkinter # Zum Erstellen von GUIs
|
|
|
|
|
|
import numpy as np # Numpy Import
|
|
|
import sys
|
|
|
import sys
|
|
|
|
|
|
|
|
|
#Einlesen des Bildes
|
|
|
|
|
|
|
|
|
# Einlesen des Bildes
|
|
|
script_dir = sys.path[0]
|
|
|
script_dir = sys.path[0]
|
|
|
path = script_dir[:-4] + "Beispielbilder\lena.jpg"
|
|
|
path = script_dir[:-4] + "Beispielbilder\lena.jpg"
|
|
|
image = cv2.imread(path) #Einlesen des Bildes (noch hardcodiert, sollte dann in GUI gehen)
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def gammaCorrection(v):
|
|
|
|
|
|
if (v <= 0.04045 * 255):
|
|
|
|
|
|
return ((v / 255) / 12.92)
|
|
|
|
|
|
elif (v > 0.04045 * 255):
|
|
|
|
|
|
return (((v / 255) + 0.055) / 1.055) ** 2.4
|
|
|
|
|
|
else:
|
|
|
|
|
|
print("Ungültiger Wert!!")
|
|
|
|
|
|
return 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def reverseGammaCorrection(v_reverse):
|
|
|
|
|
|
if (v_reverse <= 0.0031308):
|
|
|
|
|
|
return 255 * (12.92 * v_reverse)
|
|
|
|
|
|
elif (v_reverse > 0.0031308):
|
|
|
|
|
|
return 255 * (1.055 * v_reverse ** 0.41666 - 0.055)
|
|
|
|
|
|
else:
|
|
|
|
|
|
print("Ungültiger Wert!!!")
|
|
|
|
|
|
return 1
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
|
|
|
'''
|
|
|
'''
|
|
|
0.4124564 0.3575761 0.1804375 Transformationsmatrix fuer XYZ Werte aus gegebenen RGB Werten!
|
|
|
0.4124564 0.3575761 0.1804375 Transformationsmatrix fuer XYZ Werte aus gegebenen RGB Werten!
|
|
|
|
|
|
|
|
|
0.0193339 0.1191920 0.9503041
|
|
|
0.0193339 0.1191920 0.9503041
|
|
|
'''
|
|
|
'''
|
|
|
|
|
|
|
|
|
RGB2XYZ = np.array([[0.4124564,0.3575761,0.1804375],[0.2126729,0.7151522,0.0721750],[0.0193339,0.1191920,0.9503041]])
|
|
|
|
|
|
|
|
|
RGB2XYZ = np.array(
|
|
|
|
|
|
[[0.4124564, 0.3575761, 0.1804375],
|
|
|
|
|
|
[0.2126729, 0.7151522, 0.0721750],
|
|
|
|
|
|
[0.0193339, 0.1191920, 0.9503041]])
|
|
|
|
|
|
|
|
|
'''
|
|
|
'''
|
|
|
3.2404542 -1.5371385 -0.4985314 Transformationsmatrix fuer RGB Werte aus gegebenen XYZ Werten!
|
|
|
3.2404542 -1.5371385 -0.4985314 Transformationsmatrix fuer RGB Werte aus gegebenen XYZ Werten!
|
|
|
|
|
|
|
|
|
0.0556434 -0.2040259 1.0572252
|
|
|
0.0556434 -0.2040259 1.0572252
|
|
|
'''
|
|
|
'''
|
|
|
|
|
|
|
|
|
XYZ2RGB = np.array([[3.2404542,-1.5371385,-0.4985314],[-0.9692660,1.8760108,0.0415560],[0.0556434,-0.2040259,1.0572252]])
|
|
|
|
|
|
|
|
|
XYZ2RGB = np.array(
|
|
|
|
|
|
[[3.2404542, -1.5371385, -0.4985314],
|
|
|
|
|
|
[-0.9692660, 1.8760108, 0.0415560],
|
|
|
|
|
|
[0.0556434, -0.2040259, 1.0572252]])
|
|
|
|
|
|
|
|
|
'''
|
|
|
'''
|
|
|
0.4002 0.7076 −0.0808 Transformationsmatrix fuer LMS Werte aus gegebenen XYZ Werten
|
|
|
0.4002 0.7076 −0.0808 Transformationsmatrix fuer LMS Werte aus gegebenen XYZ Werten
|
|
|
|
|
|
|
|
|
0 0 0.9182
|
|
|
0 0 0.9182
|
|
|
'''
|
|
|
'''
|
|
|
|
|
|
|
|
|
M_HPE = np.array([[0.4002,0.7076,-0.0808],[-0.2263,1.1653,0.0457],[0,0,0.9182]])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
M_HPE = np.array([[0.4002, 0.7076, -0.0808],
|
|
|
|
|
|
[-0.2263, 1.1653, 0.0457],
|
|
|
|
|
|
[0, 0, 0.9182]])
|
|
|
|
|
|
|
|
|
# for i in range(rows): #Durchgehen aller Pixel des Bildes
|
|
|
# for i in range(rows): #Durchgehen aller Pixel des Bildes
|
|
|
# for j in range(cols):
|
|
|
# for j in range(cols):
|
|
|
|
|
|
|
|
|
# #Umwandlungsalgorithmus
|
|
|
# #Umwandlungsalgorithmus
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cv2.namedWindow("Display") #Displaywindow erstellen
|
|
|
|
|
|
cv2.imshow("Display",image) #Bild zeigen
|
|
|
|
|
|
cv2.waitKey(0) #Fenster offen halten
|
|
|
|
|
|
|
|
|
cv2.namedWindow("Display") # Displaywindow erstellen
|
|
|
|
|
|
cv2.imshow("Display", image) # Bild zeigen
|
|
|
|
|
|
cv2.waitKey(0) # Fenster offen halten
|