Add gaussian blur/sharpen capability.
This commit is contained in:
@@ -12,10 +12,16 @@ Nodes for basic frame interpolation without the use of AI.
|
||||
### Simple Frame Interpolation (VFI)
|
||||
|
||||
A node for doing very simple frame interpolation operations.
|
||||
Uses basic operations (bicubic, lanczos, etc.) to blend the frames together.
|
||||
Uses basic operations (bicubic, lanczos, etc.) to blend the frames together.
|
||||
Also can apply a gaussian blur or sharpen effect to blend frames.
|
||||
Blur will apply a motion blur effect, while sharpen will reduce motion blur.
|
||||
|
||||
| | |
|
||||
|--------------|--------------------------------------------------------------------------|
|
||||
| images | Image frames to interpolate. |
|
||||
| scale_method | Method used to interpolate the frames. |
|
||||
| multiplier | Value to multiply the number of frames by. Not limited to whole numbers. |
|
||||
| Input | Description |
|
||||
|----------------|---------------------------------------------------------------------------|
|
||||
| images | Image frames to interpolate. |
|
||||
| scale_method | Method used to interpolate the frames. |
|
||||
| multiplier | Value to multiply the number of frames by. Not limited to whole numbers. |
|
||||
| gaussian_blur | Enable gaussian blur/sharpen frame blending. |
|
||||
| blur_radius | The spread of the blur to neighboring frames. |
|
||||
| blur_sigma | Intensity of blur/sharpen. Positive values blur, negative values sharpen. |
|
||||
| sharpen_alpha | When blur_sigma is negative, this increases the sharpen intensity. |
|
||||
@@ -1,6 +1,8 @@
|
||||
import torch
|
||||
import torch.nn.functional as F
|
||||
|
||||
from nodes import ImageScale
|
||||
from comfy_extras.nodes_post_processing import Blur, Sharpen
|
||||
|
||||
class Simple_Frame_Interpolation:
|
||||
scale_methods = ["nearest", "nearest-exact", "bilinear", "area", "bicubic", "lanczos", "bislerp"]
|
||||
@@ -8,8 +10,12 @@ class Simple_Frame_Interpolation:
|
||||
def INPUT_TYPES(s):
|
||||
return {"required": {
|
||||
"images": ("IMAGE", ),
|
||||
"scale_method": (s.scale_methods, {"default": "bislerp"}),
|
||||
"multiplier": ("FLOAT", {"default": 0.5, "min": 0.01, "max": 20.0, "step": 0.01}),
|
||||
"scale_method": (s.scale_methods, {"default": "nearest-exact"}),
|
||||
"multiplier": ("FLOAT", {"default": 0.5, "min": 0.01, "step": 0.01}),
|
||||
"gaussian_blur": ("BOOLEAN", {"default": True}),
|
||||
"blur_radius": ("INT", { "default": 2, "min": 1, "step": 1 }),
|
||||
"blur_sigma": ("FLOAT", { "default": 0.3, "min": -10.0, "max": 10.0, "step": 0.1}),
|
||||
"sharpen_alpha": ("FLOAT", { "default": 0.1, "min": 0.0, "max": 5.0, "step": 0.01 }),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -20,12 +26,23 @@ class Simple_Frame_Interpolation:
|
||||
CATEGORY = "Simple-VFI"
|
||||
|
||||
@torch.no_grad()
|
||||
def process(self, images, scale_method, multiplier):
|
||||
def process(self, images, scale_method, multiplier, gaussian_blur, blur_radius, blur_sigma, sharpen_alpha):
|
||||
B, H, W, C = images.shape
|
||||
new_frame_count = max(round(B * multiplier), 1)
|
||||
|
||||
images = images.flatten(0, 2).unflatten(0, (1, B, H * W))
|
||||
images, = ImageScale.upscale(self, images, scale_method, H * W, new_frame_count, crop="disabled")
|
||||
|
||||
if gaussian_blur and blur_radius != 0 and blur_sigma != 0:
|
||||
B2, H2, W2, C2 = images.shape
|
||||
|
||||
images.flatten(1, 2).unsqueeze(2)
|
||||
if blur_sigma > 0:
|
||||
images, = Blur.blur(self, images, blur_radius, blur_sigma)
|
||||
elif blur_sigma < 0 :
|
||||
images, = Sharpen.sharpen(self, images, blur_radius, -blur_sigma, sharpen_alpha)
|
||||
images.flatten(1, 2).unflatten(1, (H2, W2))
|
||||
|
||||
images = images.flatten(0, 2).unflatten(0, (new_frame_count, H, W))
|
||||
|
||||
return (images,)
|
||||
|
||||
Reference in New Issue
Block a user