-
Notifications
You must be signed in to change notification settings - Fork 0
/
blur_text.py
29 lines (24 loc) · 1.01 KB
/
blur_text.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from PIL import Image, ImageFilter
# Load the image
img_path = "test_data/samurai.jpg"
img_saves = ["test_data/blur/samurai_blurred.jpg", "test_data/blur/samurai_fully_blurred.jpg"]
for img_save in img_saves:
image = Image.open(img_path)
# Specify the area to blur (x0, y0, x1, y1)
if "fully" in img_save:
box_1 = (80, 20, 550, 100)
box_2 = (20, 570, 620, 650)
cropped_image_1 = image.crop(box_1)
cropped_image_2 = image.crop(box_2)
blurred_image_1 = cropped_image_1.filter(ImageFilter.GaussianBlur(radius=15))
blurred_image_2 = cropped_image_2.filter(ImageFilter.GaussianBlur(radius=15))
image.paste(blurred_image_1, box_1)
image.paste(blurred_image_2, box_2)
else:
box_1 = (80, 20, 550, 100)
cropped_image_1 = image.crop(box_1)
blurred_image_1 = cropped_image_1.filter(ImageFilter.GaussianBlur(radius=15))
image.paste(blurred_image_1, box_1)
# Save or display the image
image.save(img_save)
# image.show()