Blur.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import cv2
  2. import numpy
  3. import Tool
  4. from PF2.Tools import Contrast
  5. class Blur(Tool.Tool):
  6. def on_init(self):
  7. self.id = "blur"
  8. self.name = "Blur"
  9. self.icon_path = "ui/PF2_Icons/Blur.png"
  10. self.properties = [
  11. # Detailer
  12. Tool.Property("enabled", "Blur", "Header", False, has_toggle=True, has_button=False),
  13. Tool.Property("method", "Method", "Combo", 1, options=[
  14. "Guassian",
  15. "Average",
  16. "Median"
  17. ]),
  18. Tool.Property("strength", "Strength", "Slider", 5, max=100, min=0),
  19. ]
  20. def on_update(self, image):
  21. im = image
  22. if(self.props["enabled"].get_value()):
  23. strength = self.props["strength"].get_value()
  24. method = self.props["method"].get_value()
  25. if (strength > 0):
  26. blur_size = 2 * round((round(strength) + 1) / 2) - 1
  27. if(method == 0):
  28. im = cv2.GaussianBlur(im, (int(blur_size), int(blur_size)), 0)
  29. elif(method == 1):
  30. im = cv2.blur(im, (int(blur_size), int(blur_size)))
  31. elif(method == 2):
  32. im = cv2.medianBlur(im, int(blur_size))
  33. return im