Browse Source

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.
master
Max Sponsel 4 years ago
parent
commit
08881f47cf
1 changed files with 8 additions and 10 deletions
  1. 8
    10
      Code/Dyschromasie-Applikation.py

+ 8
- 10
Code/Dyschromasie-Applikation.py View File

# 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):
# 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.T_reversed.dot(sim_mat).dot(self.T).dot(np.flipud(self.cb_image[i, j])))
self.cb_image[i, j] = self.T_reversed.dot(sim_mat).dot(self.T).dot(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):
# 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.T_reversed.dot(sim_mat).dot(self.T).dot(np.flipud(self.cb_image[i, j])))
self.cb_image[i, j] = self.T_reversed.dot(sim_mat).dot(self.T).dot(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')
# 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.T_reversed.dot(sim_mat).dot(self.T).dot(np.flipud(self.cb_image[i, j])))
self.cb_image[i, j] = self.T_reversed.dot(sim_mat).dot(self.T).dot(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')
# 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
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)
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)
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…
Cancel
Save