From 8d9f2a8a179e32abeb42eacd1ca2b0b955a5fe25 Mon Sep 17 00:00:00 2001 From: Artemy Date: Sun, 16 Apr 2023 10:46:55 +0300 Subject: [PATCH] feat: sharpen method --- methods/bulk_methods.py | 5 +++++ processing/bulk.py | 24 +++++++++++++++--------- tabs/Bulk processing/app.py | 2 +- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/methods/bulk_methods.py b/methods/bulk_methods.py index 8c6ddc0..735c232 100644 --- a/methods/bulk_methods.py +++ b/methods/bulk_methods.py @@ -7,3 +7,8 @@ def canny_edge(file_name): image = image.convert("L") return image.filter(ImageFilter.FIND_EDGES) + + +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 40c4a0c..d7cbf8a 100644 --- a/processing/bulk.py +++ b/processing/bulk.py @@ -2,7 +2,7 @@ import ffmpeg import os from processing.utils import generate_name, get_date_text, generate_name_with_file_name -from methods.bulk_methods import canny_edge +from methods.bulk_methods import canny_edge, sharpen def images_to_video(directory, fps, img_ext, img_name_format, video_name, video_ext, video_dir): @@ -29,11 +29,17 @@ def video_to_images(video_path, img_ext): def bulk_processing(directory, out_directory, method): date = get_date_text() if method == "canny edge": - for file in os.listdir(directory): - img = canny_edge(os.path.join(directory, file)) - if out_directory: - img_out_path = os.path.join(out_directory, file) - else: - img_out_path = generate_name_with_file_name( - name=file, subfolder=os.path.join("images", date)) - img.save(img_out_path) + run_bulk(canny_edge, directory, out_directory, date) + elif method == "sharpen": + run_bulk(sharpen, directory, out_directory, date) + + +def run_bulk(func, directory, out_directory, date): + for file in os.listdir(directory): + img = func(os.path.join(directory, file)) + if out_directory: + img_out_path = os.path.join(out_directory, file) + else: + img_out_path = generate_name_with_file_name( + name=file, subfolder=os.path.join("images", date)) + img.save(img_out_path) diff --git a/tabs/Bulk processing/app.py b/tabs/Bulk processing/app.py index f1a86d0..9416d4f 100644 --- a/tabs/Bulk processing/app.py +++ b/tabs/Bulk processing/app.py @@ -9,7 +9,7 @@ with gr.Blocks() as app: directory = gr.Text( placeholder="A directory with many images.", lines=1, label="Directory") method = gr.Dropdown( - choices=["canny edge"], value="canny edge", label="Method") + choices=["canny edge", "sharpen"], value="canny edge", label="Method") with gr.Accordion("Advanced settings", open=False) as acc: out_dir = gr.Text(