Blur.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. height, width = image.shape[:2]
  26. size = (height*width)
  27. mul = numpy.math.sqrt(size) / 1064.416 #numpy.math.sqrt(1132982.0)
  28. if (strength > 0):
  29. blur_size = 2 * round((round(strength*mul) + 1) / 2) - 1
  30. if(method == 0):
  31. im = cv2.GaussianBlur(im, (int(blur_size), int(blur_size)), 0)
  32. elif(method == 1):
  33. im = cv2.blur(im, (int(blur_size), int(blur_size)))
  34. elif(method == 2):
  35. im = cv2.medianBlur(im, int(blur_size))
  36. return im