BLUR-39: Add simple method of blurring.
This commit is contained in:
parent
e990582cbd
commit
b27f4930db
@ -1,8 +1,8 @@
|
||||
import os
|
||||
|
||||
from typing import List
|
||||
|
||||
from PIL import Image, ImageDraw, ImageFont, ImageFilter
|
||||
from PIL.Image import composite
|
||||
|
||||
from BlurMe.ml.element_detection import BoundBox
|
||||
|
||||
@ -26,15 +26,21 @@ def show_image_with_boxes(
|
||||
img.save(out_image_path)
|
||||
|
||||
|
||||
def blur_image_with_boxes(
|
||||
def blur_boxes_on_image(
|
||||
in_image_path: str, bounding_boxes: List[BoundBox], out_image_path: str = None
|
||||
):
|
||||
img = Image.open(in_image_path)
|
||||
blur_img = img.filter(ImageFilter.GaussianBlur(radius=7))
|
||||
mask = Image.new("L", img.size, 255)
|
||||
draw_mask = ImageDraw.Draw(mask)
|
||||
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 box.object == "plate":
|
||||
draw_mask.rectangle(box.get_params(), fill=0)
|
||||
elif box.object == "face":
|
||||
draw_mask.rectangle(box.get_params(), fill=0)
|
||||
mask = mask.filter(ImageFilter.GaussianBlur(radius=3))
|
||||
img = composite(img, blur_img, mask)
|
||||
if not out_image_path:
|
||||
out_image_path = (
|
||||
in_image_path.split(".")[0] + "_blurred." + in_image_path.split(".")[1]
|
||||
|
Loading…
Reference in New Issue
Block a user