Lookup-Table für die Entfrenung der Gamma Korrektur implementiert
Zur Besseren Performance wird eine Lookup Table benötigt. Diese gleicht dynamisch alles Werte ab anstatt bei jedem einzelnen Pixelwert die Berechnung durchzuführen.
This commit is contained in:
parent
105b6689b8
commit
804bc74885
@ -3,7 +3,7 @@ import PIL
|
|||||||
import tkinter as tk
|
import tkinter as tk
|
||||||
import cv2
|
import cv2
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from Farbaenderung import gammaCorrection, reverseGammaCorrection, Dyschromasie
|
from Farbaenderung import Dyschromasie
|
||||||
from Scrollbar import ScrollFrame
|
from Scrollbar import ScrollFrame
|
||||||
|
|
||||||
root = tk.Tk()
|
root = tk.Tk()
|
||||||
|
@ -2,19 +2,28 @@ import numpy as np
|
|||||||
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))
|
||||||
|
|
||||||
@ -40,6 +49,9 @@ class Dyschromasie:
|
|||||||
[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],
|
||||||
@ -56,13 +68,10 @@ class Dyschromasie:
|
|||||||
# 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):
|
self.cb_image = cv2.LUT(self.img_mat, removeGammaCorrectionLUT)
|
||||||
for j in range(self.cols):
|
|
||||||
for x in range(3):
|
|
||||||
self.cb_image[i, j, x] = gammaCorrection(self.img_mat[i, j, x])
|
|
||||||
|
|
||||||
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):
|
||||||
@ -74,6 +83,7 @@ class Dyschromasie:
|
|||||||
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
|
||||||
|
|
||||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user