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 cv2
|
||||
import numpy as np
|
||||
from Farbaenderung import gammaCorrection, reverseGammaCorrection, Dyschromasie
|
||||
from Farbaenderung import Dyschromasie
|
||||
from Scrollbar import ScrollFrame
|
||||
|
||||
root = tk.Tk()
|
||||
|
@ -2,14 +2,23 @@ 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:
|
||||
@ -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,10 +68,7 @@ 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))
|
||||
|
||||
@ -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
|
||||
|
||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user