BLUR-37: Add simple method of blurring.

This commit is contained in:
Gosia 2023-12-19 09:35:45 +01:00
parent 9f55a0c034
commit e990582cbd
1 changed files with 18 additions and 2 deletions

View File

@ -2,7 +2,7 @@ import os
from typing import List from typing import List
from PIL import Image, ImageDraw, ImageFont from PIL import Image, ImageDraw, ImageFont, ImageFilter
from BlurMe.ml.element_detection import BoundBox from BlurMe.ml.element_detection import BoundBox
@ -24,3 +24,19 @@ def show_image_with_boxes(
in_image_path.split(".")[0] + "_out." + in_image_path.split(".")[1] in_image_path.split(".")[0] + "_out." + in_image_path.split(".")[1]
) )
img.save(out_image_path) img.save(out_image_path)
def blur_image_with_boxes(
in_image_path: str, bounding_boxes: List[BoundBox], out_image_path: str = None
):
img = Image.open(in_image_path)
for box in bounding_boxes:
if box.selected:
cropped = img.crop(box.get_params())
blurred = cropped.filter(ImageFilter.GaussianBlur(radius=10))
img.paste(blurred, box.get_params())
if not out_image_path:
out_image_path = (
in_image_path.split(".")[0] + "_blurred." + in_image_path.split(".")[1]
)
img.save(out_image_path)