Vereinfachung des Codes mit cv2.cvtColor
Statt das Array doppelt mit der flipud Funktion zu spiegeln, wird es direkt im Einleseprozess von BGR(OpenCV) zu RGB(Pillow und Algorithmus) konvertiert.
This commit is contained in:
parent
e62ea2a23e
commit
08881f47cf
@ -49,6 +49,7 @@ class Protanopie(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):
|
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):
|
||||||
@ -57,12 +58,10 @@ class Protanopie(Dyschromasie):
|
|||||||
# 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):
|
||||||
self.cb_image[i, j] = np.flipud(
|
self.cb_image[i, j] = self.T_reversed.dot(sim_mat).dot(self.T).dot(self.cb_image[i, j])
|
||||||
self.T_reversed.dot(sim_mat).dot(self.T).dot(np.flipud(self.cb_image[i, j])))
|
|
||||||
|
|
||||||
self.sim_image = np.copy(self.cb_image)
|
self.sim_image = np.copy(self.cb_image)
|
||||||
self.sim_image = self.sim_image.astype('uint8')
|
self.sim_image = self.sim_image.astype('uint8')
|
||||||
|
|
||||||
# Rücktransformation der Gammawerte
|
# Rücktransformation der Gammawerte
|
||||||
for i in range(self.rows):
|
for i in range(self.rows):
|
||||||
for j in range(self.cols):
|
for j in range(self.cols):
|
||||||
@ -89,8 +88,7 @@ class Deuteranopie(Dyschromasie):
|
|||||||
# 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):
|
||||||
self.cb_image[i, j] = np.flipud(
|
self.cb_image[i, j] = self.T_reversed.dot(sim_mat).dot(self.T).dot(self.cb_image[i, j])
|
||||||
self.T_reversed.dot(sim_mat).dot(self.T).dot(np.flipud(self.cb_image[i, j])))
|
|
||||||
|
|
||||||
self.sim_image = np.copy(self.cb_image)
|
self.sim_image = np.copy(self.cb_image)
|
||||||
self.sim_image = self.sim_image.astype('uint8')
|
self.sim_image = self.sim_image.astype('uint8')
|
||||||
@ -121,8 +119,7 @@ class Tritanopie(Dyschromasie):
|
|||||||
# 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):
|
||||||
self.cb_image[i, j] = np.flipud(
|
self.cb_image[i, j] = self.T_reversed.dot(sim_mat).dot(self.T).dot(self.cb_image[i, j])
|
||||||
self.T_reversed.dot(sim_mat).dot(self.T).dot(np.flipud(self.cb_image[i, j])))
|
|
||||||
|
|
||||||
self.sim_image = np.copy(self.cb_image)
|
self.sim_image = np.copy(self.cb_image)
|
||||||
self.sim_image = self.sim_image.astype('uint8')
|
self.sim_image = self.sim_image.astype('uint8')
|
||||||
@ -229,6 +226,7 @@ def browse():
|
|||||||
# Einspeichern der Path-Informationen
|
# Einspeichern der Path-Informationen
|
||||||
global img, rows, cols, kanaele
|
global img, rows, cols, kanaele
|
||||||
img = cv2.imread(path)
|
img = cv2.imread(path)
|
||||||
|
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
|
||||||
rows, cols, kanaele = img.shape
|
rows, cols, kanaele = img.shape
|
||||||
|
|
||||||
|
|
||||||
@ -236,7 +234,7 @@ def simulate():
|
|||||||
global img, rows, cols, kanaele, sim_pro, sim_deut, sim_tri
|
global img, rows, cols, kanaele, sim_pro, sim_deut, sim_tri
|
||||||
if sim_deut.get():
|
if sim_deut.get():
|
||||||
d = Deuteranopie(img, rows, cols, kanaele, simGrad.get()/100)
|
d = Deuteranopie(img, rows, cols, kanaele, simGrad.get()/100)
|
||||||
display_array_deut = cv2.cvtColor(np.copy(d.Simulate()), cv2.COLOR_BGR2RGB)
|
display_array_deut = d.Simulate()
|
||||||
|
|
||||||
T = tk.Text(SB.frame, height=1, width=15)
|
T = tk.Text(SB.frame, height=1, width=15)
|
||||||
T.grid(columnspan=5)
|
T.grid(columnspan=5)
|
||||||
@ -249,7 +247,7 @@ def simulate():
|
|||||||
sim_pic_deut.grid(columnspan=5)
|
sim_pic_deut.grid(columnspan=5)
|
||||||
elif sim_tri.get():
|
elif sim_tri.get():
|
||||||
t = Tritanopie(img, rows, cols, kanaele, simGrad.get()/100)
|
t = Tritanopie(img, rows, cols, kanaele, simGrad.get()/100)
|
||||||
display_array_tri = cv2.cvtColor(np.copy(t.Simulate()), cv2.COLOR_BGR2RGB)
|
display_array_tri = t.Simulate()
|
||||||
|
|
||||||
T = tk.Text(SB.frame, height=1, width=15)
|
T = tk.Text(SB.frame, height=1, width=15)
|
||||||
T.grid(columnspan=5)
|
T.grid(columnspan=5)
|
||||||
@ -262,7 +260,7 @@ def simulate():
|
|||||||
sim_pic_tri.grid(columnspan=5)
|
sim_pic_tri.grid(columnspan=5)
|
||||||
elif sim_pro.get():
|
elif sim_pro.get():
|
||||||
p = Protanopie(img, rows, cols, kanaele, simGrad.get()/100)
|
p = Protanopie(img, rows, cols, kanaele, simGrad.get()/100)
|
||||||
display_array_pro = cv2.cvtColor(np.copy(p.Simulate()), cv2.COLOR_BGR2RGB)
|
display_array_pro = p.Simulate()
|
||||||
|
|
||||||
T = tk.Text(SB.frame, height=1, width=15)
|
T = tk.Text(SB.frame, height=1, width=15)
|
||||||
T.grid(columnspan=5)
|
T.grid(columnspan=5)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user