mirror of
https://github.com/artegoser/image-pluser-webui.git
synced 2024-11-05 20:23:58 +03:00
fix: name of method and formatting
This commit is contained in:
parent
1b259c886f
commit
fbc9112fba
9 changed files with 61 additions and 45 deletions
|
@ -1,7 +1,7 @@
|
|||
from PIL import Image, ImageFilter
|
||||
|
||||
|
||||
def canny_edge(file_name):
|
||||
def edge(file_name):
|
||||
image = Image.open(file_name)
|
||||
|
||||
image = image.convert("L")
|
||||
|
|
|
@ -6,8 +6,7 @@ def denoise(files):
|
|||
bias = 1
|
||||
image = Image.open(files[0])
|
||||
for file in tqdm(files):
|
||||
|
||||
alpha = 1/bias
|
||||
alpha = 1 / bias
|
||||
|
||||
im2 = Image.open(file)
|
||||
im3 = Image.blend(image, im2, alpha)
|
||||
|
@ -31,7 +30,7 @@ def startracks(files):
|
|||
|
||||
def noise_extractor(files):
|
||||
image = Image.open(files[0])
|
||||
for file in tqdm(files, unit=' images'):
|
||||
for file in tqdm(files, unit=" images"):
|
||||
im2 = Image.open(file)
|
||||
im3 = ImageChops.difference(image, im2)
|
||||
image = im3
|
||||
|
@ -41,7 +40,7 @@ def noise_extractor(files):
|
|||
|
||||
def untrack(files):
|
||||
image = Image.open(files[0])
|
||||
for file in tqdm(files, unit=' images'):
|
||||
for file in tqdm(files, unit=" images"):
|
||||
im2 = Image.open(file)
|
||||
im3 = ImageChops.darker(image, im2)
|
||||
image = im3
|
||||
|
|
|
@ -1,35 +1,38 @@
|
|||
|
||||
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, sharpen
|
||||
from methods.bulk_methods import edge, sharpen
|
||||
|
||||
|
||||
def images_to_video(directory, fps, img_ext, img_name_format, video_name, video_ext, video_dir):
|
||||
def images_to_video(
|
||||
directory, fps, img_ext, img_name_format, video_name, video_ext, video_dir
|
||||
):
|
||||
images_pattern = os.path.join(directory, f"{img_name_format}.{img_ext}")
|
||||
|
||||
if video_dir:
|
||||
video_path = os.path.join(video_dir, f"{video_name}.{video_ext}")
|
||||
else:
|
||||
video_path = generate_name(
|
||||
extension=video_ext, name=video_name, subfolder="videos")
|
||||
extension=video_ext, name=video_name, subfolder="videos"
|
||||
)
|
||||
|
||||
ffmpeg.input(images_pattern,
|
||||
framerate=fps).output(video_path, pix_fmt='yuv420p').global_args("-y").run()
|
||||
ffmpeg.input(images_pattern, framerate=fps).output(
|
||||
video_path, pix_fmt="yuv420p"
|
||||
).global_args("-y").run()
|
||||
|
||||
|
||||
def video_to_images(video_path, img_ext):
|
||||
|
||||
images_pattern = generate_name(
|
||||
extension=img_ext, name=f"%d", subfolder=os.path.join("images", get_date_text()))
|
||||
extension=img_ext, name=f"%d", subfolder=os.path.join("images", get_date_text())
|
||||
)
|
||||
|
||||
ffmpeg.input(video_path).output(images_pattern).run()
|
||||
|
||||
|
||||
def bulk_processing(directory, out_directory, method):
|
||||
date = get_date_text()
|
||||
if method == "canny edge":
|
||||
run_bulk(canny_edge, directory, out_directory, date)
|
||||
if method == "Edge detection":
|
||||
run_bulk(edge, directory, out_directory, date)
|
||||
elif method == "sharpen":
|
||||
run_bulk(sharpen, directory, out_directory, date)
|
||||
|
||||
|
@ -41,5 +44,6 @@ def run_bulk(func, directory, out_directory, date):
|
|||
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))
|
||||
name=file, subfolder=os.path.join("images", date)
|
||||
)
|
||||
img.save(img_out_path)
|
||||
|
|
|
@ -4,7 +4,6 @@ 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))
|
||||
|
|
|
@ -2,8 +2,9 @@ import os
|
|||
import datetime
|
||||
|
||||
|
||||
def generate_name(name=False, subfolder="stacked", extension="png", format='%Y-%m-%d_%H-%M-%S'):
|
||||
|
||||
def generate_name(
|
||||
name=False, subfolder="stacked", extension="png", format="%Y-%m-%d_%H-%M-%S"
|
||||
):
|
||||
os.makedirs(os.path.join(".", "output", subfolder), exist_ok=True)
|
||||
|
||||
if name is False or name == "":
|
||||
|
@ -13,11 +14,10 @@ def generate_name(name=False, subfolder="stacked", extension="png", format='%Y-%
|
|||
|
||||
|
||||
def generate_name_with_file_name(name, subfolder):
|
||||
|
||||
os.makedirs(os.path.join(".", "output", subfolder), exist_ok=True)
|
||||
|
||||
return os.path.join(".", "output", subfolder, name)
|
||||
|
||||
|
||||
def get_date_text(format='%Y-%m-%d_%H-%M-%S'):
|
||||
def get_date_text(format="%Y-%m-%d_%H-%M-%S"):
|
||||
return datetime.datetime.now().strftime(format)
|
||||
|
|
|
@ -3,17 +3,22 @@ from processing.bulk import bulk_processing
|
|||
|
||||
with gr.Blocks() as app:
|
||||
gr.Markdown(
|
||||
"Mass processing of images one at a time and saving to video if needed. # **WIP, not working**")
|
||||
"Mass processing of images one at a time and saving to video if needed. # **WIP, not working**"
|
||||
)
|
||||
with gr.Row():
|
||||
with gr.Column():
|
||||
directory = gr.Text(
|
||||
placeholder="A directory with many images.", lines=1, label="Directory")
|
||||
placeholder="A directory with many images.", lines=1, label="Directory"
|
||||
)
|
||||
method = gr.Dropdown(
|
||||
choices=["canny edge", "sharpen"], 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(
|
||||
label="Output directory", placeholder="The directory where the processed photos will be saved. If not specified `./output/images`")
|
||||
label="Output directory",
|
||||
placeholder="The directory where the processed photos will be saved. If not specified `./output/images`",
|
||||
)
|
||||
submit = gr.Button("Submit")
|
||||
submit.click(
|
||||
fn=bulk_processing,
|
||||
|
|
|
@ -4,27 +4,42 @@ from processing.bulk import images_to_video
|
|||
with gr.Blocks() as app:
|
||||
gr.Markdown("Convert images to video.")
|
||||
directory = gr.Text(
|
||||
placeholder="A directory with many images of the same size", label="Directory")
|
||||
placeholder="A directory with many images of the same size", label="Directory"
|
||||
)
|
||||
|
||||
fps = gr.Number(label="FPS", value=30, min=0)
|
||||
|
||||
with gr.Accordion("Advanced settings", open=False) as acc:
|
||||
video_name = gr.Text(
|
||||
label="Video name", placeholder="Video name e.g. video. If not specified will be generated by time")
|
||||
video_ext = gr.Dropdown(label="Video extension", choices=[
|
||||
"mp4"], value="mp4")
|
||||
label="Video name",
|
||||
placeholder="Video name e.g. video. If not specified will be generated by time",
|
||||
)
|
||||
video_ext = gr.Dropdown(label="Video extension", choices=["mp4"], value="mp4")
|
||||
video_dir = gr.Text(
|
||||
label="Video directory", placeholder="The directory where the video will be saved. If not specified `./output/videos`")
|
||||
label="Video directory",
|
||||
placeholder="The directory where the video will be saved. If not specified `./output/videos`",
|
||||
)
|
||||
|
||||
img_ext = gr.Dropdown(label="Image extension", choices=[
|
||||
"png", "jpg"], value="png")
|
||||
img_ext = gr.Dropdown(
|
||||
label="Image extension", choices=["png", "jpg"], value="png"
|
||||
)
|
||||
img_name_format = gr.Text(
|
||||
label="Image name format", placeholder="ffmpeg pattern e.g. %04d is (0000.png)", value="%d")
|
||||
label="Image name format",
|
||||
placeholder="ffmpeg pattern e.g. %04d is (0000.png)",
|
||||
value="%d",
|
||||
)
|
||||
|
||||
submit = gr.Button("Submit")
|
||||
|
||||
submit.click(
|
||||
fn=images_to_video,
|
||||
inputs=[directory, fps, img_ext, img_name_format,
|
||||
video_name, video_ext, video_dir],
|
||||
inputs=[
|
||||
directory,
|
||||
fps,
|
||||
img_ext,
|
||||
img_name_format,
|
||||
video_name,
|
||||
video_ext,
|
||||
video_dir,
|
||||
],
|
||||
)
|
||||
|
|
|
@ -2,15 +2,14 @@ import gradio as gr
|
|||
from processing.bulk import video_to_images
|
||||
|
||||
with gr.Blocks() as app:
|
||||
gr.Markdown(
|
||||
"Convert video to images.")
|
||||
gr.Markdown("Convert video to images.")
|
||||
with gr.Row():
|
||||
with gr.Column():
|
||||
|
||||
video = gr.Video(label="Video")
|
||||
|
||||
with gr.Column():
|
||||
format = gr.Radio(
|
||||
choices=["png", "jpg"], value="png", label="Format of image")
|
||||
choices=["png", "jpg"], value="png", label="Format of image"
|
||||
)
|
||||
submit = gr.Button("Submit")
|
||||
submit.click(fn=video_to_images, inputs=[video, format])
|
||||
|
|
|
@ -1,6 +1 @@
|
|||
tabs = [
|
||||
"Stacking",
|
||||
"Bulk processing",
|
||||
"Images to video",
|
||||
"Video to images"
|
||||
]
|
||||
tabs = ["Stacking", "Bulk processing", "Images to video", "Video to images"]
|
||||
|
|
Loading…
Reference in a new issue