MainWindowModel.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. # Qt import
  2. # import
  3. import numpy as np
  4. # miam import
  5. import miam.image.Image as MIMG
  6. import miam.image.imageType as MTYPE
  7. import miam.workflow.WFWorkflow as MWF
  8. class MainWindowModel(object):
  9. """
  10. class for main window model
  11. """
  12. def __init__(self, controller):
  13. # attributes
  14. # ----------------------------------------
  15. # reference to MainWindowController
  16. self.controller = controller
  17. # input image (miam.image.Image)
  18. # only change when load called
  19. self.inputImage = None
  20. # list of processes
  21. self.workflow = None
  22. # smaller images to faster computation display
  23. self.image = None
  24. # method(s)
  25. # ------------------------------------------------------------------------
  26. def readImage(self, filename):
  27. # read image
  28. # store input : no processing applyed
  29. self.inputImage = MIMG.Image.readImage(filename)
  30. # reset self.image list and self.process
  31. self.image = None
  32. # compute smaller image 4 interactive
  33. width = self.controller.screenSize[0].width()
  34. self.image = self.inputImage.resize((width,None))
  35. # default processing for HDR iamge
  36. if self.inputImage.type == MTYPE.imageType.HDR:
  37. self.image = self.image.removeZeros(0.5)
  38. return [self.image]
  39. def readWorkflow(self, filename):
  40. # read workflow
  41. # note: read include compile
  42. self.workflow = MWF.WFWorkflow.readWorkflow(filename)
  43. # ------------------------------------------------------------------------
  44. def compute(self):
  45. # return list of image
  46. resImgs = []
  47. if self.workflow:
  48. # check if input image
  49. if self.inputImage:
  50. # compute with self.image for faster computation
  51. self.workflow.compute(self.image)
  52. for leaf in self.workflow.leafs:
  53. resImgs.append(leaf.image)
  54. else: # no input image
  55. self.controller.statusMessage("compute: no input image ! Open image first ...")
  56. else : # no workflow
  57. self.controller.statusMessage("compute: no workflow ! Load workflow first ...")
  58. return resImgs
  59. # ------------------------------------------------------------------------