mirror of
https://github.com/artegoser/image-pluser-webui.git
synced 2024-12-22 16:53:49 +03:00
refactor: methods
This commit is contained in:
parent
3f1d13c1c0
commit
09346cb114
6 changed files with 35 additions and 24 deletions
|
@ -2,6 +2,8 @@ from PIL import Image, ImageFilter
|
|||
from skimage import feature
|
||||
import numpy as np
|
||||
|
||||
methods = ["Sharpen", "Edge detection", "Canny edge detection"]
|
||||
|
||||
|
||||
def edge(file_name):
|
||||
image = Image.open(file_name)
|
||||
|
@ -22,3 +24,10 @@ def canny_edge(file_name):
|
|||
def sharpen(file_name):
|
||||
image = Image.open(file_name)
|
||||
return image.filter(ImageFilter.SHARPEN)
|
||||
|
||||
|
||||
methods_funcs = {
|
||||
"Sharpen": sharpen,
|
||||
"Edge detection": edge,
|
||||
"Canny edge detection": canny_edge,
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@ from PIL import Image, ImageChops
|
|||
from tqdm import tqdm
|
||||
import numpy as np
|
||||
|
||||
methods = ["Denoise", "StarTracks", "Noise extractor", "Untrack"]
|
||||
|
||||
|
||||
def denoise(files):
|
||||
images = [np.asarray(Image.open(file)) for file in tqdm(files)]
|
||||
|
@ -36,3 +38,11 @@ def untrack(files):
|
|||
image = im3
|
||||
|
||||
return image
|
||||
|
||||
|
||||
methods_funcs = {
|
||||
"Denoise": denoise,
|
||||
"StarTracks": startracks,
|
||||
"Noise extractor": noise_extractor,
|
||||
"Untrack": untrack,
|
||||
}
|
||||
|
|
|
@ -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, canny_edge
|
||||
from methods.bulk_methods import methods_funcs
|
||||
|
||||
|
||||
def images_to_video(
|
||||
|
@ -31,12 +31,7 @@ def video_to_images(video_path, img_ext):
|
|||
|
||||
def bulk_processing(directory, out_directory, method):
|
||||
date = get_date_text()
|
||||
if method == "Edge detection":
|
||||
run_bulk(edge, directory, out_directory, date)
|
||||
elif method == "Canny edge detection":
|
||||
run_bulk(canny_edge, directory, out_directory, date)
|
||||
elif method == "Sharpen":
|
||||
run_bulk(sharpen, directory, out_directory, date)
|
||||
run_bulk(methods_funcs[method], directory, out_directory, date)
|
||||
|
||||
|
||||
def run_bulk(func, directory, out_directory, date):
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
from methods.stack_methods import denoise, startracks, noise_extractor, untrack
|
||||
from methods.stack_methods import (
|
||||
methods_funcs,
|
||||
)
|
||||
import os
|
||||
from processing.utils import generate_name
|
||||
|
||||
|
@ -6,16 +8,8 @@ from processing.utils import generate_name
|
|||
def stacking(dir, method):
|
||||
files = os.listdir(dir)
|
||||
files = list(map(lambda x: os.path.join(dir, x), files))
|
||||
files = list(filter(lambda x: x.endswith(".png"), files))
|
||||
|
||||
if method == "denoise":
|
||||
img = denoise(files)
|
||||
elif method == "startracks":
|
||||
img = startracks(files)
|
||||
elif method == "noise extractor":
|
||||
img = noise_extractor(files)
|
||||
elif method == "untrack":
|
||||
img = untrack(files)
|
||||
img = methods_funcs[method](files)
|
||||
|
||||
name = generate_name()
|
||||
img.save(name)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import gradio as gr
|
||||
from processing.bulk import bulk_processing
|
||||
from methods.bulk_methods import methods
|
||||
|
||||
with gr.Blocks() as app:
|
||||
gr.Markdown(
|
||||
|
@ -11,8 +12,8 @@ with gr.Blocks() as app:
|
|||
placeholder="A directory with many images.", lines=1, label="Directory"
|
||||
)
|
||||
method = gr.Dropdown(
|
||||
choices=["Edge detection", "Canny edge detection", "sharpen"],
|
||||
value="Sharpen",
|
||||
choices=methods,
|
||||
value=methods[0],
|
||||
label="Method",
|
||||
)
|
||||
|
||||
|
|
|
@ -1,18 +1,20 @@
|
|||
import gradio as gr
|
||||
from processing.stacking import stacking
|
||||
from methods.stack_methods import methods
|
||||
|
||||
with gr.Blocks() as app:
|
||||
gr.Markdown("Stacking images.")
|
||||
with gr.Row():
|
||||
with gr.Column():
|
||||
directory = gr.Text(
|
||||
placeholder="A directory with many images of the same size", lines=1, label="Directory")
|
||||
methods = gr.Dropdown(
|
||||
choices=["denoise", "startracks", "noise extractor", "untrack"], value="denoise", label="Method")
|
||||
placeholder="A directory with many images of the same size",
|
||||
lines=1,
|
||||
label="Directory",
|
||||
)
|
||||
method = gr.Dropdown(choices=methods, value=methods[0], label="Method")
|
||||
submit = gr.Button("Submit")
|
||||
|
||||
with gr.Column():
|
||||
output = gr.Gallery()
|
||||
|
||||
submit.click(stacking, inputs=[
|
||||
directory, methods], outputs=[output])
|
||||
submit.click(stacking, inputs=[directory, method], outputs=[output])
|
||||
|
|
Loading…
Add table
Reference in a new issue