Dieses Projekt dient der digitalen Umwandlung von Bildern in simulierte Darstellung aus Sicht eines rot-grün-blinden Menschen.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Dyschromasie-Applikation.py 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. from PIL import Image, ImageTk
  2. import PIL
  3. import tkinter as tk
  4. from tkinter import filedialog, messagebox
  5. import cv2
  6. import numpy as np
  7. from Farbaenderung import gammaCorrection, reverseGammaCorrection, Dyschromasie
  8. from Scrollbar import ScrollFrame
  9. root = tk.Tk()
  10. simGrad = tk.IntVar(root)
  11. root.title("Projekt Dyschromasie")
  12. SB = ScrollFrame(root)
  13. img = np.array([])
  14. rows = 0
  15. cols = 0
  16. kanaele = 0
  17. sim_pro = tk.IntVar(root)
  18. sim_deut = tk.IntVar(root)
  19. sim_tri = tk.IntVar(root)
  20. simulationsGradient = tk.Scale(SB.frame, from_=0, to_=100, variable=simGrad, orient='horizontal')
  21. simulationsGradient.grid(column= 0, row = 1, columnspan=10)
  22. def browse():
  23. # Auswahl des FilePaths
  24. try:
  25. path = tk.filedialog.askopenfilename(filetypes=[("Image File", '.jpg'),("Image File", '.png')])
  26. im = Image.open(path)
  27. except:
  28. tk.messagebox.showerror(title='Datenfehler', message='Kein Bild gefunden/ausgewählt')
  29. global simulateButton
  30. if len(path) > 0:
  31. simulateButton.config(state='active')
  32. # Anzeigen des Bildes
  33. tkimage = ImageTk.PhotoImage(im)
  34. myvar = tk.Label(SB.frame, image=tkimage)
  35. myvar.image = tkimage
  36. myvar.grid(columnspan=5)
  37. # Einspeichern der Path-Informationen
  38. global img, rows, cols, kanaele
  39. img = cv2.imread(path)
  40. img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
  41. #img = cv2.GaussianBlur(img, (3, 3), 0)
  42. rows, cols, kanaele = img.shape
  43. def simulate():
  44. global img, rows, cols, kanaele, sim_pro, sim_deut, sim_tri
  45. if sim_deut.get():
  46. d = Dyschromasie(img, rows, cols, kanaele, simGrad.get()/100, 'd')
  47. display_array_deut = np.copy(d.Simulate()).astype('uint8')
  48. T = tk.Text(SB.frame, height=1, width=15)
  49. T.grid(columnspan=5)
  50. print_string = "Deutranop(" + str(round(d.sim_faktor*100)) + "%)"
  51. T.insert('current', print_string)
  52. conv_SimulationPic_deut = ImageTk.PhotoImage(image=PIL.Image.fromarray(display_array_deut))
  53. sim_pic_deut = tk.Label(SB.frame, image=conv_SimulationPic_deut)
  54. sim_pic_deut.Image = conv_SimulationPic_deut
  55. sim_pic_deut.grid(columnspan=5)
  56. elif sim_tri.get():
  57. t = Dyschromasie(img, rows, cols, kanaele, simGrad.get()/100, 't')
  58. display_array_tri = np.copy(t.Simulate()).astype('uint8')
  59. T = tk.Text(SB.frame, height=1, width=15)
  60. T.grid(columnspan=5)
  61. print_string = "Tritanop(" + str(round(t.sim_faktor * 100)) + "%)"
  62. T.insert('current', print_string)
  63. conv_SimulationPic_tri = ImageTk.PhotoImage(image=PIL.Image.fromarray(display_array_tri))
  64. sim_pic_tri = tk.Label(SB.frame, image=conv_SimulationPic_tri)
  65. sim_pic_tri.Image = conv_SimulationPic_tri
  66. sim_pic_tri.grid(columnspan=5)
  67. elif sim_pro.get():
  68. p = Dyschromasie(img, rows, cols, kanaele, simGrad.get()/100, 'p')
  69. display_array_pro = np.copy(p.Simulate()).astype('uint8')
  70. T = tk.Text(SB.frame, height=1, width=15)
  71. T.grid(columnspan=5)
  72. print_string = "Protanop(" + str(round(p.sim_faktor * 100)) + "%)"
  73. T.insert('current', print_string)
  74. conv_SimulationPic_pro = ImageTk.PhotoImage(image=PIL.Image.fromarray(display_array_pro))
  75. sim_pic_pro = tk.Label(SB.frame, image=conv_SimulationPic_pro)
  76. sim_pic_pro.Image = conv_SimulationPic_pro
  77. sim_pic_pro.grid(columnspan=5)
  78. btn = tk.Button(SB.frame, text="Browse", width=25, command=browse, bg='light blue')
  79. btn.grid(column=0, row=0, columnspan=2)
  80. simulateButton = tk.Button(SB.frame, text="Simulate", width=25, command=simulate, bg='light blue')
  81. simulateButton.grid(column=1, row=0, columnspan=2)
  82. simulateButton.config(state='disabled')
  83. checkButton_p = tk.Checkbutton(SB.frame, text="Protanop", variable=sim_pro, onvalue=1, offvalue=0, height=5, width=20)
  84. checkButton_d = tk.Checkbutton(SB.frame, text="Deutanop", variable=sim_deut, onvalue=1, offvalue=0, height=5, width=20)
  85. checkButton_t = tk.Checkbutton(SB.frame, text="Tritanop", variable=sim_tri, onvalue=1, offvalue=0, height=5, width=20)
  86. checkButton_p.grid(column=0, row=2)
  87. checkButton_d.grid(column=1, row=2)
  88. checkButton_t.grid(column=2, row=2)
  89. SB.update()
  90. root.mainloop()