From 3f1d13c1c0385594a35d13c97332a67997b76da5 Mon Sep 17 00:00:00 2001 From: Artemy Date: Mon, 17 Apr 2023 20:20:27 +0300 Subject: [PATCH] feat: canny edge --- methods/bulk_methods.py | 10 ++++++++++ processing/bulk.py | 6 ++++-- tabs/Bulk processing/app.py | 4 +++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/methods/bulk_methods.py b/methods/bulk_methods.py index 785b6aa..75bcd15 100644 --- a/methods/bulk_methods.py +++ b/methods/bulk_methods.py @@ -1,4 +1,6 @@ from PIL import Image, ImageFilter +from skimage import feature +import numpy as np def edge(file_name): @@ -9,6 +11,14 @@ def edge(file_name): return image.filter(ImageFilter.FIND_EDGES) +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)) + + def sharpen(file_name): image = Image.open(file_name) return image.filter(ImageFilter.SHARPEN) diff --git a/processing/bulk.py b/processing/bulk.py index e8996bf..4cb3657 100644 --- a/processing/bulk.py +++ b/processing/bulk.py @@ -1,7 +1,7 @@ import ffmpeg import os from processing.utils import generate_name, get_date_text, generate_name_with_file_name -from methods.bulk_methods import edge, sharpen +from methods.bulk_methods import edge, sharpen, canny_edge def images_to_video( @@ -33,7 +33,9 @@ def bulk_processing(directory, out_directory, method): date = get_date_text() if method == "Edge detection": run_bulk(edge, directory, out_directory, date) - elif method == "sharpen": + elif method == "Canny edge detection": + run_bulk(canny_edge, directory, out_directory, date) + elif method == "Sharpen": run_bulk(sharpen, directory, out_directory, date) diff --git a/tabs/Bulk processing/app.py b/tabs/Bulk processing/app.py index 80f2170..065169f 100644 --- a/tabs/Bulk processing/app.py +++ b/tabs/Bulk processing/app.py @@ -11,7 +11,9 @@ with gr.Blocks() as app: placeholder="A directory with many images.", lines=1, label="Directory" ) method = gr.Dropdown( - choices=["canny edge", "sharpen"], value="canny edge", label="Method" + choices=["Edge detection", "Canny edge detection", "sharpen"], + value="Sharpen", + label="Method", ) with gr.Accordion("Advanced settings", open=False) as acc: