From f6e3225afd126026f3f5b93d2a4412be5d01819d Mon Sep 17 00:00:00 2001 From: Artemy Date: Sun, 30 Apr 2023 21:01:03 +0300 Subject: [PATCH] feat: histogram matching --- methods/two_to_one_methods.py | 12 ++++++++++++ processing/stacking.py | 4 +--- processing/two_to_one.py | 10 ++++++++++ tabs/Two images to one/app.py | 17 +++++++++++++++++ tabs/__init__.py | 8 +++++++- 5 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 methods/two_to_one_methods.py create mode 100644 processing/two_to_one.py create mode 100644 tabs/Two images to one/app.py diff --git a/methods/two_to_one_methods.py b/methods/two_to_one_methods.py new file mode 100644 index 0000000..655524b --- /dev/null +++ b/methods/two_to_one_methods.py @@ -0,0 +1,12 @@ +from skimage.exposure import match_histograms +import numpy as np +from PIL import Image + + +def histogram_matching(img1, img2): + return Image.fromarray(match_histograms(img1, img2, channel_axis=-1)) + + +methods_funcs = {"Histogram matching": histogram_matching} + +methods = list(methods_funcs.keys()) diff --git a/processing/stacking.py b/processing/stacking.py index 45200ac..d69315f 100644 --- a/processing/stacking.py +++ b/processing/stacking.py @@ -1,6 +1,4 @@ -from methods.stack_methods import ( - methods_funcs, -) +from methods.stack_methods import methods_funcs import os from processing.utils import generate_name diff --git a/processing/two_to_one.py b/processing/two_to_one.py new file mode 100644 index 0000000..8953fb6 --- /dev/null +++ b/processing/two_to_one.py @@ -0,0 +1,10 @@ +from methods.two_to_one_methods import methods_funcs +from processing.utils import generate_name + + +def two_to_one(img1, img2, method): + img = methods_funcs[method](img1, img2) + out_path = generate_name(subfolder="two_to_one") + img.save(out_path) + + return [out_path] diff --git a/tabs/Two images to one/app.py b/tabs/Two images to one/app.py new file mode 100644 index 0000000..f38ce4c --- /dev/null +++ b/tabs/Two images to one/app.py @@ -0,0 +1,17 @@ +import gradio as gr +from processing.two_to_one import two_to_one +from methods.two_to_one_methods import methods + +with gr.Blocks() as app: + gr.Markdown("Get one image from two.") + with gr.Row(): + with gr.Column(): + img1 = gr.Image() + img2 = gr.Image() + method = gr.Dropdown(choices=methods, value=methods[0], label="Method") + submit = gr.Button("Submit") + + with gr.Column(): + output = gr.Gallery() + + submit.click(two_to_one, inputs=[img1, img2, method], outputs=[output]) diff --git a/tabs/__init__.py b/tabs/__init__.py index ebf178a..65e828b 100644 --- a/tabs/__init__.py +++ b/tabs/__init__.py @@ -1 +1,7 @@ -tabs = ["Stacking", "Bulk processing", "Images to video", "Video to images"] +tabs = [ + "Stacking", + "Bulk processing", + "Two images to one", + "Images to video", + "Video to images", +]