Correct blur/sharpen algorithm. Add batch_size.

This commit is contained in:
ComplexRobot
2025-03-16 17:57:18 -07:00
parent cf00f9b704
commit 8f9a770cb9
3 changed files with 37 additions and 17 deletions
+10 -9
View File
@@ -16,12 +16,13 @@ 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.
| 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. |
| 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. |
| batch_size | Number of pixels to operate on at a time. Adjust for a speed/memory trade-off. |
| 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. |
+26 -7
View File
@@ -1,7 +1,10 @@
import torch
import torch.nn.functional as F
from nodes import ImageScale
from comfy_extras.nodes_post_processing import Blur, Sharpen
import comfy.model_management as mm
class Simple_Frame_Interpolation:
scale_methods = ["nearest", "nearest-exact", "bilinear", "area", "bicubic", "lanczos", "bislerp"]
@@ -11,6 +14,7 @@ class Simple_Frame_Interpolation:
"images": ("IMAGE", ),
"scale_method": (s.scale_methods, {"default": "nearest-exact"}),
"multiplier": ("FLOAT", {"default": 0.5, "min": 0.01, "step": 0.01}),
"batch_size": ("INT", { "default": 15, "min": 1, "step": 1 }),
"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}),
@@ -25,7 +29,8 @@ class Simple_Frame_Interpolation:
CATEGORY = "Simple-VFI"
@torch.no_grad()
def process(self, images, scale_method, multiplier, gaussian_blur, blur_radius, blur_sigma, sharpen_alpha):
def process(self, images, scale_method, multiplier, batch_size, gaussian_blur, blur_radius, blur_sigma, sharpen_alpha):
device = mm.get_torch_device()
B, H, W, C = images.shape
new_frame_count = max(round(B * multiplier), 1)
@@ -35,12 +40,26 @@ class Simple_Frame_Interpolation:
if gaussian_blur and blur_radius != 0 and blur_sigma != 0:
B2, H2, W2, C2 = images.shape
images.flatten(0, 2).unflatten(0, (W2, H2, 1))
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(0, 2).unflatten(0, (1, H2, W2))
images = images.permute(0, 2, 1, 3)
images = images.flatten(0, 2).unflatten(0, (W2, H2, 1))
for i in range(0, W2, batch_size):
end = min(i + batch_size, W2)
current_image = images[i:end, :, :, :]
current_image = current_image.permute(0, 3, 1, 2).contiguous().to(device)
current_image = F.interpolate(current_image, size=(H2, 2 * blur_radius + 1), mode='nearest-exact')
current_image = current_image.permute(0, 2, 3, 1)
print(f"{i} -> {current_image.shape}")
if blur_sigma > 0:
current_image, = Blur.blur(self, current_image, blur_radius, blur_sigma)
elif blur_sigma < 0 :
current_image, = Sharpen.sharpen(self, current_image, blur_radius, -blur_sigma, sharpen_alpha)
images[i:end] = current_image[:, :, blur_radius:-blur_radius, :].cpu()
images = images.flatten(0, 2).unflatten(0, (1, W2, H2))
images = images.permute(0, 2, 1, 3)
images = images.flatten(0, 2).unflatten(0, (new_frame_count, H, W))
+1 -1
View File
@@ -1,7 +1,7 @@
[project]
name = "ComfyUI-Simple-VFI"
description = "Nodes for simple frame interpolation without the use of AI. Uses standard image operations to blend frames together."
version = "1.0.0"
version = "1.0.1"
license = "LICENSE"
dependencies = ["open-clip-torch"]