image-pluser-webui/methods/bulk_methods.py

44 lines
895 B
Python
Raw Normal View History

2023-04-16 10:36:29 +03:00
from PIL import Image, ImageFilter
2023-04-17 20:20:27 +03:00
from skimage import feature
import numpy as np
2023-04-16 10:36:29 +03:00
2023-04-16 18:40:08 +03:00
def edge(file_name):
2023-04-16 10:36:29 +03:00
image = Image.open(file_name)
image = image.convert("L")
return image.filter(ImageFilter.FIND_EDGES)
2023-04-16 10:46:55 +03:00
2023-04-17 20:20:27 +03:00
def canny_edge(file_name):
image = Image.open(file_name)
image = image.convert("L")
image = np.asarray(image)
return Image.fromarray(feature.canny(image, sigma=2))
2023-04-26 19:04:08 +03:00
def blur(file_name):
image = Image.open(file_name)
return image.filter(ImageFilter.BLUR)
def grayscale(file_name):
image = Image.open(file_name)
return image.convert("L")
2023-04-16 10:46:55 +03:00
def sharpen(file_name):
image = Image.open(file_name)
return image.filter(ImageFilter.SHARPEN)
2023-04-18 13:16:16 +03:00
methods_funcs = {
"Sharpen": sharpen,
"Edge detection": edge,
"Canny edge detection": canny_edge,
2023-04-26 19:04:08 +03:00
"Grayscale": grayscale,
"Blur": blur,
2023-04-18 13:16:16 +03:00
}
2023-04-21 14:25:22 +03:00
methods = list(methods_funcs.keys())