Skip to content

Commit fbcc5c0

Browse files
committed
added the ImageTransition node.
1 parent 7e72e50 commit fbcc5c0

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ Enhanced the official UpscaleImageWithModel node by adding a judge. If the input
8989
## ImageCompositeWatermark
9090
This node is designed to composite a watermark into the destination image. It can select the position of the watermark, resize the watermark according to the input ratio, and add a margin to the watermark.
9191

92+
## ImageTransition
93+
This node is designed to generate a transition image between two images. It can generate a transition image between two images.
94+
9295
## DetectorForNSFW
9396
This node adapts the original model and inference code from [nudenet](https://github.com/notAI-tech/NudeNet.git) for use with Comfy. A small 10MB default model, [320n.onnx](https://github.com/notAI-tech/NudeNet?tab=readme-ov-file#available-models), is provided. If you wish to use other models from that repository, download the [ONNX model](https://github.com/notAI-tech/NudeNet?tab=readme-ov-file#available-models) and place it in the models/nsfw directory, then set the appropriate detect_size.
9497

py/node_image.py

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from comfy_extras.nodes_mask import ImageCompositeMasked
22
import torch
3-
3+
import torch.nn.functional as F
44
class ImageCompositeWatermark(ImageCompositeMasked):
55
@classmethod
66
def INPUT_TYPES(s):
@@ -56,14 +56,54 @@ def composite_watermark(self, destination, watermark, position, resize_ratio, ma
5656

5757
return self.composite(destination, watermark, x, y, False, mask)
5858

59+
class ImageTransition:
60+
@classmethod
61+
def INPUT_TYPES(s):
62+
return {
63+
"required": {
64+
"first_image": ("IMAGE",),
65+
"last_image": ("IMAGE",),
66+
"frames": ("INT", {"default": 24, "min": 2, "max": 120, "step": 1}),
67+
"transition_type": (["uniform", "smooth"], {"default": "uniform"}),
68+
"smooth_effect": ("FLOAT", {"default": 1.0, "min": 0.1, "max": 10.0, "step": 0.1}),
69+
}
70+
}
71+
72+
RETURN_TYPES = ("IMAGE",)
73+
FUNCTION = "generate_transition"
74+
CATEGORY = "utils/image"
5975

76+
def generate_transition(self, first_image, last_image, frames, transition_type="uniform", smooth_effect=1.0):
77+
# 生成插值权重
78+
if transition_type == "uniform":
79+
weights = torch.linspace(0, 1, frames)
80+
else: # sigmoid
81+
x = torch.linspace(-20, 20, frames)
82+
weights = torch.sigmoid(x / smooth_effect)
83+
84+
# 创建输出张量列表
85+
output_frames = []
86+
87+
# 生成过渡帧
88+
for w in weights:
89+
# 使用权重进行插值
90+
transition_frame = first_image * (1 - w) + last_image * w
91+
output_frames.append(transition_frame)
92+
93+
# 将所有帧拼接在一起
94+
result = torch.cat(output_frames, dim=0)
95+
96+
return (result,)
97+
6098
NODE_CLASS_MAPPINGS = {
6199

62100
#image
63101
"ImageCompositeWatermark": ImageCompositeWatermark,
102+
"ImageTransition": ImageTransition,
64103
}
65104

66105
NODE_DISPLAY_NAME_MAPPINGS = {
67106
# Image
68107
"ImageCompositeWatermark": "Image Composite Watermark",
108+
"ImageTransition": "Image Transition",
69109
}

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[project]
22
name = "comfyui-utils-nodes"
33
description = "Nodes:LoadImageWithSwitch, ImageBatchOneOrMore, ModifyTextGender, GenderControlOutput, ImageCompositeMaskedWithSwitch, ImageCompositeMaskedOneByOne, ColorCorrectOfUtils, SplitMask, MaskFastGrow, CheckpointLoaderSimpleWithSwitch, ImageResizeTo8x, MatchImageRatioToPreset, UpscaleImageWithModelIfNeed, MaskFromFaceModel, MaskCoverFourCorners, DetectorForNSFW, DeepfaceAnalyzeFaceAttributes etc."
4-
version = "1.2.3"
4+
version = "1.2.4"
55
license = { file = "LICENSE" }
66
dependencies = []
77

0 commit comments

Comments
 (0)