Fattal.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import getpass
  2. import os
  3. import subprocess
  4. import shutil
  5. import cv2
  6. from HDR.Methods import Method
  7. from Tool import Property
  8. class Fattal(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", "--gpu", "-a", "/tmp/hdr-%s/OUT_" % getpass.getuser(), "-o",
  13. "/tmp/hdr-%s/OUT" % getpass.getuser()] + files
  14. print(command)
  15. subprocess.call(command)
  16. return ["/tmp/hdr-%s/OUT.hdr" % getpass.getuser(),]
  17. def run(self, files, output, full_width, full_height):
  18. im = cv2.imread(files[0], 2 | 1)
  19. ph, pw = im.shape[:2]
  20. cv2.imwrite(files[0], cv2.resize(im, (int(full_width), int(full_height)), interpolation = cv2.INTER_AREA))
  21. command = "pfsin --radiance '%s' | pfstmo_fattal02 -b %.2f -g %.2f -s %.2f -n %.2f -d %.2f -w %.2f -k %.2f -- | pfsout '%s'" % \
  22. (files[0],
  23. self.props["beta"].get_value(),
  24. self.props["gamma"].get_value(),
  25. self.props["saturation"].get_value(),
  26. self.props["noise"].get_value(),
  27. self.props["detail"].get_value(),
  28. self.props["white"].get_value(),
  29. self.props["black"].get_value(),
  30. "/tmp/hdr-out-%s.tiff" % getpass.getuser())
  31. print(command)
  32. os.system(command)
  33. im = cv2.imread("/tmp/hdr-out-%s.tiff" % getpass.getuser(), 2 | 1)
  34. cv2.imwrite(output, cv2.resize(im, (int(pw), int(ph)), interpolation=cv2.INTER_AREA))
  35. os.unlink("/tmp/hdr-out-%s.tiff" % getpass.getuser())
  36. shutil.rmtree("/tmp/hdr-%s" % getpass.getuser())
  37. def on_init(self):
  38. self.id = "Fattal"
  39. self.name = "Fattal"
  40. self.properties = [
  41. Property("beta", "Beta", "Slider", 0.9, min=0.6, max=1),
  42. Property("gamma", "Gamma", "Slider", 0.8, min=0.1, max=1),
  43. Property("saturation", "Saturation", "Slider", 0.8, min=0.1, max=1),
  44. Property("detail", "Lightness", "Slider", 3, min=0, max=9),
  45. Property("noise", "Noise Reduction", "Slider", 0.0, min=0, max=1),
  46. Property("white", "Overexposure", "Slider", 0.5, min=0, max=1),
  47. Property("black", "Underexposure", "Slider", 0.5, min=0, max=1),
  48. ]