|
|
|
|
|
|
|
|
import cv2
|
|
|
import cv2
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def gammaCorrection(v):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def createGammaLookup():
|
|
|
|
|
|
return np.array([removeGammaCorrection(i) for i in np.arange(0, 256)]).astype("float64")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def createReverseGammaLookup():
|
|
|
|
|
|
return np.array([applyGammaCorrection(i/255) for i in np.arange(0.0, 256.0)]).astype("uint8")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def removeGammaCorrection(v):
|
|
|
if v <= 0.04045 * 255:
|
|
|
if v <= 0.04045 * 255:
|
|
|
return (v / 255) / 12.92
|
|
|
return (v / 255) / 12.92
|
|
|
elif v > 0.04045 * 255:
|
|
|
elif v > 0.04045 * 255:
|
|
|
return (((v / 255) + 0.055) / 1.055) ** 2.4
|
|
|
return (((v / 255) + 0.055) / 1.055) ** 2.4
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def reverseGammaCorrection(v_reverse):
|
|
|
|
|
|
|
|
|
def applyGammaCorrection(v_reverse):
|
|
|
if abs(v_reverse) <= 0.0031308:
|
|
|
if abs(v_reverse) <= 0.0031308:
|
|
|
return round(255 * (12.92 * abs(v_reverse)))
|
|
|
return round(255 * (12.92 * abs(v_reverse)))
|
|
|
elif abs(v_reverse) > 0.0031308:
|
|
|
elif abs(v_reverse) > 0.0031308:
|
|
|
if (round(255 * (1.055 * abs(v_reverse) ** 0.41666 - 0.055))) > 255:
|
|
|
if (round(255 * (1.055 * abs(v_reverse) ** 0.41666 - 0.055))) > 255:
|
|
|
return 255 - (round(255 * (1.055 * abs(v_reverse) ** 0.41666 - 0.055))- 255)
|
|
|
|
|
|
|
|
|
return 255 - (round(255 * (1.055 * abs(v_reverse) ** 0.41666 - 0.055)) - 255)
|
|
|
else:
|
|
|
else:
|
|
|
return round(255 * (1.055 * abs(v_reverse) ** 0.41666 - 0.055))
|
|
|
return round(255 * (1.055 * abs(v_reverse) ** 0.41666 - 0.055))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[0.02980165, -0.19318073, 1.16364789]])
|
|
|
[0.02980165, -0.19318073, 1.16364789]])
|
|
|
|
|
|
|
|
|
def Simulate(self):
|
|
|
def Simulate(self):
|
|
|
|
|
|
|
|
|
|
|
|
removeGammaCorrectionLUT = createGammaLookup()
|
|
|
|
|
|
|
|
|
if self.sim_kind == 'p':
|
|
|
if self.sim_kind == 'p':
|
|
|
sim_mat = np.array([[(1 - self.sim_faktor), 1.05118294 * self.sim_faktor, -0.05116099 * self.sim_faktor],
|
|
|
sim_mat = np.array([[(1 - self.sim_faktor), 1.05118294 * self.sim_faktor, -0.05116099 * self.sim_faktor],
|
|
|
[0, 1, 0],
|
|
|
[0, 1, 0],
|
|
|
|
|
|
|
|
|
# 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 j in range(self.cols):
|
|
|
|
|
|
for x in range(3):
|
|
|
|
|
|
self.cb_image[i, j, x] = gammaCorrection(self.img_mat[i, j, x])
|
|
|
|
|
|
|
|
|
self.cb_image = cv2.LUT(self.img_mat, removeGammaCorrectionLUT)
|
|
|
|
|
|
|
|
|
rechen_Mat = np.copy(self.T_reversed.dot(sim_mat).dot(self.T))
|
|
|
rechen_Mat = np.copy(self.T_reversed.dot(sim_mat).dot(self.T))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Einzelne Pixelwertberechnung
|
|
|
# Einzelne Pixelwertberechnung
|
|
|
for i in range(self.rows):
|
|
|
for i in range(self.rows):
|
|
|
for j in range(self.cols):
|
|
|
for j in range(self.cols):
|
|
|
|
|
|
|
|
|
for i in range(self.rows):
|
|
|
for i in range(self.rows):
|
|
|
for j in range(self.cols):
|
|
|
for j in range(self.cols):
|
|
|
for x in range(3):
|
|
|
for x in range(3):
|
|
|
self.sim_image[i, j, x] = reverseGammaCorrection(self.cb_image[i, j, x])
|
|
|
|
|
|
|
|
|
self.sim_image[i, j, x] = applyGammaCorrection(self.cb_image[i, j, x])
|
|
|
|
|
|
|
|
|
return self.sim_image
|
|
|
return self.sim_image
|
|
|
|
|
|
|