MainWindow.py 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. # import
  2. # ------------------------------------------------------------------------------------------
  3. import os, sys, math
  4. import multiprocessing as mp
  5. import matplotlib
  6. import numpy as np
  7. import easygui
  8. import colour
  9. # import Qt
  10. from PyQt5.QtWidgets import QMainWindow, QAction, QApplication, QMenu
  11. from PyQt5.QtWidgets import QWidget, QLabel, QFileDialog
  12. from PyQt5.QtWidgets import QHBoxLayout # QSlider
  13. from PyQt5.QtGui import QIcon, QPixmap, QImage
  14. from PyQt5 import QtCore, QtWidgets
  15. # QT matplotlib
  16. # miam import
  17. import miam.image.Image as MIMG
  18. import miam.histogram.Histogram as MHIST
  19. import miam.image.channel
  20. import miam.utils
  21. # gui import
  22. import gui.guiController.MainWindowController as gMWC
  23. import gui.guiView.ImageWidget as gIW
  24. import gui.guiView.FigureWidget as gFW
  25. # ------------------------------------------------------------------------------------------
  26. # MIAM project 2020
  27. # ------------------------------------------------------------------------------------------
  28. # author: remi.cozot@univ-littoral.fr
  29. # ------------------------------------------------------------------------------------------
  30. class MainWindow(QMainWindow):
  31. """
  32. MainWindow(Vue)
  33. """
  34. # version 0.1
  35. # features:
  36. # load image
  37. # switch between display mode
  38. #
  39. def __init__(self, controller = None):
  40. super().__init__()
  41. # attributes
  42. self.controller = controller
  43. # build menu
  44. self.buildFileMenu()
  45. self.buildDisplayMenu()
  46. self.buildWorkflowMenu()
  47. # setGeometry
  48. self.setWindowGeometry()
  49. # title
  50. self.setWindowTitle('MIAM - Rémi Cozot (c) 2020')
  51. # status bar
  52. self.statusBar().showMessage('Welcome to MIAM: Multidimensional Image Aesthetics Model!')
  53. # centralWidgets
  54. self.imageWidgets = []
  55. self.layout = QHBoxLayout()
  56. self.container = QWidget()
  57. #self.setCentralWidget(self.container)
  58. # methods
  59. def resizeEvent(self, event):
  60. if self.controller.displayMode != gMWC.mainWidgetDisplayMode.HIST :
  61. for cw in self.imageWidgets:
  62. cw.resize()
  63. pass
  64. # build menu
  65. # ---------------------------------------------------------
  66. def buildFileMenu(self):
  67. """
  68. XXX XXX XXX XXX
  69. """
  70. # get menubar
  71. menubar = self.menuBar()
  72. # file menu
  73. fileMenu = menubar.addMenu('&File')
  74. # Create Open image action
  75. openAction = QAction('&Open image', self)
  76. openAction.setShortcut('Ctrl+N')
  77. openAction.setStatusTip('Open image')
  78. openAction.triggered.connect(self.controller.openImage)
  79. fileMenu.addAction(openAction)
  80. fileMenu.addSeparator()
  81. # Create Open workflow action
  82. openWFAction = QAction('&Load workflow', self)
  83. openWFAction.setShortcut('Ctrl+W')
  84. openWFAction.setStatusTip('Load worflow')
  85. openWFAction.triggered.connect(self.controller.openWorkflow)
  86. fileMenu.addAction(openWFAction)
  87. def buildDisplayMenu(self):
  88. """
  89. XXX XXX XXX XXX
  90. """
  91. # get menubar
  92. menubar = self.menuBar()
  93. # file menu
  94. displayMenu = menubar.addMenu('&Display')
  95. # Create Display Input action
  96. displayInputAction = QAction('&Image', self)
  97. displayInputAction.setShortcut('Ctrl+I')
  98. displayInputAction.setStatusTip('Display image on/off')
  99. displayInputAction.triggered.connect(self.controller.displayIMG)
  100. displayMenu.addAction(displayInputAction)
  101. # Create Display Current action
  102. displayCurrentAction = QAction('&Histogram', self)
  103. displayCurrentAction.setShortcut('Ctrl+H')
  104. displayCurrentAction.setStatusTip('Display histogram on/off')
  105. displayCurrentAction.triggered.connect(self.controller.displayHIST)
  106. displayMenu.addAction(displayCurrentAction)
  107. def buildWorkflowMenu(self):
  108. """
  109. XXX XXX XXX XXX
  110. """
  111. # get menubar
  112. menubar = self.menuBar()
  113. # file menu
  114. workflowMenu = menubar.addMenu('&Workflow')
  115. # Create compute workflow action
  116. computeAction = QAction('&Compute', self)
  117. computeAction.setShortcut('Ctrl+C')
  118. computeAction.setStatusTip('Compute workflow')
  119. computeAction.triggered.connect(self.controller.compute)
  120. workflowMenu.addAction(computeAction)
  121. # setWindowGeometry
  122. def setWindowGeometry(self, scale=0.8):
  123. width = self.controller.screenSize[0].width()
  124. height = self.controller.screenSize[0].height()
  125. # geometry
  126. self.setGeometry(0, 0, math.floor(width*scale), math.floor(height*scale))
  127. # setImage
  128. def setImage(self, imgs):
  129. # get display mode from controller
  130. self.controller.dispHDR_linear # display mode for HDR linear | cctf
  131. # reset
  132. self.images = imgs
  133. self.imageWidgets = []
  134. self.layout = QtWidgets.QHBoxLayout()
  135. self.container = QtWidgets.QWidget()
  136. for img in self.images:
  137. # create an imageWidget
  138. imgW = gIW.ImageWidget(img)
  139. self.imageWidgets.append(imgW)
  140. # add ImageWidget
  141. self.layout.addWidget(imgW)
  142. if self.controller.displayMode == gMWC.mainWidgetDisplayMode.IMGnHIST:
  143. # create histogram
  144. if img.isHDR():
  145. ch = miam.image.channel.channel.Y
  146. else:
  147. ch = miam.image.channel.channel.L
  148. imgHist = MHIST.Histogram.build(img,ch)
  149. histW = gFW.FigureWidget()
  150. imgHist.plot(histW.axes)
  151. self.layout.addWidget(histW)
  152. self.container.setLayout(self.layout)
  153. self.setCentralWidget(self.container)
  154. # setDislaytoIMG
  155. def setDislaytoIMG(self):
  156. # reset
  157. self.layout = QtWidgets.QHBoxLayout()
  158. self.container = QtWidgets.QWidget()
  159. self.imageWidgets =[]
  160. for img in self.images:
  161. # create an imageWidget
  162. imgW = gIW.ImageWidget(img)
  163. self.imageWidgets.append(imgW)
  164. self.layout.addWidget(imgW)
  165. self.container.setLayout(self.layout)
  166. self.setCentralWidget(self.container)
  167. # setDislaytoIMGnHIST
  168. def setDislaytoIMGnHIST(self):
  169. # reset
  170. self.layout = QtWidgets.QHBoxLayout()
  171. self.container = QtWidgets.QWidget()
  172. self.imageWidgets =[]
  173. for img in self.images:
  174. # create an imageWidget
  175. imgW = gIW.ImageWidget(img)
  176. self.imageWidgets.append(imgW)
  177. # add ImageWidget
  178. self.layout.addWidget(imgW)
  179. # create histogram
  180. if imgW.image.isHDR():
  181. ch = miam.image.channel.channel.Y
  182. else:
  183. ch = miam.image.channel.channel.L
  184. imgHist = MHIST.Histogram.build(imgW.image,ch)
  185. histW = gFW.FigureWidget()
  186. imgHist.plot(histW.axes)
  187. self.layout.addWidget(histW)
  188. self.container.setLayout(self.layout)
  189. self.setCentralWidget(self.container)
  190. # setDislaytoIMGnHIST
  191. def setDislaytoHIST(self):
  192. # reset
  193. self.layout = QtWidgets.QHBoxLayout()
  194. self.container = QtWidgets.QWidget()
  195. self.imageWidgets =[]
  196. for img in self.images:
  197. # create an imageWidget
  198. imgW = gIW.ImageWidget(img)
  199. self.imageWidgets.append(imgW)
  200. for imgW in self.imageWidgets:
  201. # create histogram
  202. if imgW.image.isHDR():
  203. ch = miam.image.channel.channel.Y
  204. else:
  205. ch = miam.image.channel.channel.L
  206. imgHist = MHIST.Histogram.build(imgW.image,ch)
  207. histW = gFW.FigureWidget()
  208. imgHist.plot(histW.axes)
  209. self.layout.addWidget(histW)
  210. self.container.setLayout(self.layout)
  211. self.setCentralWidget(self.container)