Enfuse.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import getpass
  2. import glob
  3. import os
  4. import subprocess
  5. import shutil
  6. from HDR.Methods import Method
  7. from Tool import Property
  8. class Enfuse(Method):
  9. def stack(self, files):
  10. if(not os.path.exists("/tmp/hdr-%s" % getpass.getuser())):
  11. os.mkdir("/tmp/hdr-%s" % getpass.getuser())
  12. command = ["align_image_stack", "-m", "--gpu", "-a", "/tmp/hdr-%s/OUT_" % getpass.getuser()] + files
  13. subprocess.call(command)
  14. aligned_list = glob.glob("/tmp/hdr-%s/OUT*.tif" % getpass.getuser())
  15. aligned_list.reverse()
  16. return aligned_list
  17. def run(self, files, output, full_width, full_height):
  18. mask = self.props["mask"].options[self.props["mask"].get_value()].lower().replace(" ", "-")
  19. weight = self.props["weight"].options[self.props["weight"].get_value()].lower()
  20. colourspace = self.props["colourspace"].options[self.props["colourspace"].get_value()]
  21. command = ["enfuse", "--output=/tmp/hdr-stacked-%s.tiff" % getpass.getuser(),
  22. "--%s" % mask,
  23. "--exposure-weight-function=%s" % weight,
  24. "--blend-colorspace=%s" % colourspace,
  25. "--exposure-width=%.3f" % self.props["width"].get_value(),
  26. "-v"] + files
  27. print(command)
  28. subprocess.call(command)
  29. shutil.copyfile("/tmp/hdr-stacked-%s.tiff" % getpass.getuser(), output)
  30. shutil.rmtree("/tmp/hdr-%s" % getpass.getuser())
  31. os.unlink("/tmp/hdr-stacked-%s.tiff" % getpass.getuser())
  32. def on_init(self):
  33. self.id = "Enfuse"
  34. self.name = "Enfuse"
  35. self.properties = [
  36. Property("weight", "Weight Function", "Combo", 0, options=[
  37. "Gaussian",
  38. "Lorentzian",
  39. "Half-Sine",
  40. "Full-Sine",
  41. "Bi-Square"
  42. ]),
  43. Property("mask", "Mask Type", "Combo", 0, options=[
  44. "Soft Mask",
  45. "Hard Mask"
  46. ]),
  47. Property("colourspace", "Blend Colourspace", "Combo", 0, options=[
  48. "CIECAM",
  49. "CIELAB",
  50. "CIELUV",
  51. "IDENTITY"
  52. ]),
  53. Property("width", "Exposure Width", "Spin", 0.2, min=0, max=1)
  54. ]