-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode
More file actions
20 lines (12 loc) · 789 Bytes
/
code
File metadata and controls
20 lines (12 loc) · 789 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
from PIL import Image
def apply_filter(image_file, filter):
# Open image file
image = Image.open(image_file)
# Apply filter
image = image.filter(filter)
# Return processed image
return image
In this example, the apply_filter function takes in an image_file which is the path of image file and a filter which is the filter that you want to apply on image, it opens the image file using the Image.open() function from the Pillow library and then applies the specified filter using the image.filter() method. It then returns the processed image.
You can call this function and pass in an image file and a filter from the ImageFilter module of the Pillow library.
from PIL import ImageFilter
filtered_image = apply_filter("image.jpg", ImageFilter.BLUR)