From 938a8aaefc7902746ea31c5f9903896c19dca8a6 Mon Sep 17 00:00:00 2001 From: Charles Fettinger Date: Fri, 12 May 2023 23:23:08 -0700 Subject: [PATCH] Working Image level Luma Wipe Still has debug code - Amended due to missing blend edge color --- iz_helpers/image.py | 1 + iz_helpers/run.py | 6 +++++- iz_helpers/ui.py | 23 ++++++++++++++++------- iz_helpers/video.py | 6 +++--- 4 files changed, 25 insertions(+), 11 deletions(-) diff --git a/iz_helpers/image.py b/iz_helpers/image.py index 25917c0..8876c02 100644 --- a/iz_helpers/image.py +++ b/iz_helpers/image.py @@ -864,6 +864,7 @@ def PSLumaWipe2(a_color, b_color, luma, l_color=(255, 255, 0, 255), progress=0.0 out_color_comp = Image.alpha_composite(a_out_color, b_out_color) # ensure that the composited images have transparency a_color.putalpha(ImageOps.invert(b_color_alpha)) + #a_color.show("a_color b_color_alpha") final_image = Image.alpha_composite(a_color, out_color_comp) #end = timer() diff --git a/iz_helpers/run.py b/iz_helpers/run.py index c9cdccb..28b200d 100644 --- a/iz_helpers/run.py +++ b/iz_helpers/run.py @@ -1,6 +1,6 @@ import math, time, os import numpy as np -from PIL import Image, ImageFilter, ImageDraw +from PIL import Image, ImageFilter, ImageDraw, ImageColor from modules.ui import plaintext_to_html import modules.shared as shared from modules.processing import Processed, StableDiffusionProcessing @@ -208,6 +208,7 @@ def create_zoom( blend_mode, blend_gradient_size, blend_invert_do, + blend_color, inpainting_denoising_strength=1, inpainting_full_res=0, inpainting_padding=0, @@ -243,6 +244,7 @@ def create_zoom( blend_mode, blend_gradient_size, blend_invert_do, + blend_color, inpainting_denoising_strength, inpainting_full_res, inpainting_padding, @@ -318,6 +320,7 @@ def create_zoom_single( blend_mode, blend_gradient_size, blend_invert_do, + blend_color, inpainting_denoising_strength, inpainting_full_res, inpainting_padding, @@ -546,6 +549,7 @@ def create_zoom_single( blend_image, blend_mode, blend_gradient_size, + ImageColor.getcolor(blend_color, "RGBA"), ) print("Video saved in: " + os.path.join(script_path, out_config["video_filename"])) return ( diff --git a/iz_helpers/ui.py b/iz_helpers/ui.py index 9204677..ab25806 100644 --- a/iz_helpers/ui.py +++ b/iz_helpers/ui.py @@ -229,6 +229,7 @@ def on_ui_tabs(): value="Luma Wipe", type="index", ) + blend_invert_do = gr.Checkbox(False, label="Reverse Blend/Wipe") with gr.Row(): blend_gradient_size = gr.Slider( label="Blend Gradient size", @@ -237,13 +238,20 @@ def on_ui_tabs(): value=default_gradient_size, step=1 ) - blend_invert_do = gr.Checkbox(False, label="Reverse Blend/Wipe") - gr.Markdown( - """# Important Blend Info: -Number of Start and Stop Frame Duplication number of frames used for the blend/wipe effect. At 30 Frames per second, 30 frames is 1 second. -Blend Gradient size determines if blends extend to the border of the images. 61 is typical, higher values may result in frames around steps of your video -""" - ) + blend_color = gr.ColorPicker( + label='Blend Edge Color', + default='#ffff00' + ) + with gr.Accordion("Blend Info"): + gr.Markdown( + """# Important Blend Info: + Number of Start and Stop Frame Duplication number of frames used for the blend/wipe effect. At 30 Frames per second, 30 frames is 1 second. + Blend Gradient size determines if blends extend to the border of the images. 61 is typical, higher values may result in frames around steps of your video + + Free to use grayscale blend images can be found here: https://github.com/Oncorporation/obs-studio/tree/master/plugins/obs-transitions/data/luma_wipes + Ideas for custom blend images: https://www.pexels.com/search/gradient/ + """ + ) with gr.Tab("Outpaint"): inpainting_mask_blur = gr.Slider( @@ -326,6 +334,7 @@ Our best experience and trade-off is the R-ERSGAn4x upscaler. blend_mode, blend_gradient_size, blend_invert_do, + blend_color, ], outputs=[output_video, out_image, generation_info, html_info, html_log], ) diff --git a/iz_helpers/video.py b/iz_helpers/video.py index 4548249..45ca9e0 100644 --- a/iz_helpers/video.py +++ b/iz_helpers/video.py @@ -3,7 +3,7 @@ import imageio from .image import draw_gradient_ellipse, alpha_composite_images, blend_images, PSLumaWipe_images2 import math -def write_video(file_path, frames, fps, reversed=True, start_frame_dupe_amount=15, last_frame_dupe_amount=30, num_interpol_frames=2, blend_invert: bool = False, blend_image= None, blend_type:int = 0, blend_gradient_size: int = 63): +def write_video(file_path, frames, fps, reversed=True, start_frame_dupe_amount=15, last_frame_dupe_amount=30, num_interpol_frames=2, blend_invert: bool = False, blend_image= None, blend_type:int = 0, blend_gradient_size: int = 63, blend_color = "#ffff00"): """ Writes frames to an mp4 video file :param file_path: Path to output video, must end with .mp4 @@ -34,7 +34,7 @@ def write_video(file_path, frames, fps, reversed=True, start_frame_dupe_amount=1 elif blend_type == 2: start_frames = alpha_composite_images(frames[0], next_frame, blend_image, math.ceil(start_frame_dupe_amount), blend_invert) elif blend_type == 3: - start_frames = PSLumaWipe_images2(frames[0], next_frame, blend_image, math.ceil(start_frame_dupe_amount), blend_invert,(255,255,0,225)) + start_frames = PSLumaWipe_images2(frames[0], next_frame, blend_image, math.ceil(start_frame_dupe_amount), blend_invert,blend_color) del frames[:num_frames_replaced] print(f"Blending end: {math.ceil(last_frame_dupe_amount)} next to last frame:{-1 * (num_frames_replaced)}") @@ -43,7 +43,7 @@ def write_video(file_path, frames, fps, reversed=True, start_frame_dupe_amount=1 elif blend_type == 2: end_frames = alpha_composite_images(next_to_last_frame, frames[-1], blend_image, math.ceil(last_frame_dupe_amount), blend_invert) elif blend_type == 3: - end_frames = PSLumaWipe_images2(next_to_last_frame, frames[-1], blend_image, math.ceil(last_frame_dupe_amount), blend_invert, (255,255,0,225)) + end_frames = PSLumaWipe_images2(next_to_last_frame, frames[-1], blend_image, math.ceil(last_frame_dupe_amount), blend_invert, blend_color) frames = frames[:(-1 * num_frames_replaced)] else: start_frames = [frames[0]] * start_frame_dupe_amount