Browse Source

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.
master
Max Sponsel 3 years ago
parent
commit
804bc74885

+ 1
- 1
Code/Dyschromasie-Applikation.py View File

@@ -3,7 +3,7 @@ import PIL
import tkinter as tk
import cv2
import numpy as np
from Farbaenderung import gammaCorrection, reverseGammaCorrection, Dyschromasie
from Farbaenderung import Dyschromasie
from Scrollbar import ScrollFrame
root = tk.Tk()

+ 19
- 9
Code/Farbaenderung.py View File

@@ -2,19 +2,28 @@ import numpy as np
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:
return (v / 255) / 12.92
elif v > 0.04045 * 255:
return (((v / 255) + 0.055) / 1.055) ** 2.4
def reverseGammaCorrection(v_reverse):
def applyGammaCorrection(v_reverse):
if abs(v_reverse) <= 0.0031308:
return round(255 * (12.92 * abs(v_reverse)))
elif abs(v_reverse) > 0.0031308:
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:
return round(255 * (1.055 * abs(v_reverse) ** 0.41666 - 0.055))
@@ -40,6 +49,9 @@ class Dyschromasie:
[0.02980165, -0.19318073, 1.16364789]])
def Simulate(self):
removeGammaCorrectionLUT = createGammaLookup()
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],
@@ -56,13 +68,10 @@ class Dyschromasie:
# 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] = 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))
# Einzelne Pixelwertberechnung
for i in range(self.rows):
for j in range(self.cols):
@@ -74,6 +83,7 @@ class Dyschromasie:
for i in range(self.rows):
for j in range(self.cols):
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

BIN
Code/__pycache__/Farbaenderung.cpython-38.pyc View File


Loading…
Cancel
Save