|
1 | 1 | from comfy_extras.nodes_mask import ImageCompositeMasked
|
2 | 2 | import torch
|
3 |
| - |
| 3 | +import torch.nn.functional as F |
4 | 4 | class ImageCompositeWatermark(ImageCompositeMasked):
|
5 | 5 | @classmethod
|
6 | 6 | def INPUT_TYPES(s):
|
@@ -56,14 +56,54 @@ def composite_watermark(self, destination, watermark, position, resize_ratio, ma
|
56 | 56 |
|
57 | 57 | return self.composite(destination, watermark, x, y, False, mask)
|
58 | 58 |
|
| 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" |
59 | 75 |
|
| 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 | + |
60 | 98 | NODE_CLASS_MAPPINGS = {
|
61 | 99 |
|
62 | 100 | #image
|
63 | 101 | "ImageCompositeWatermark": ImageCompositeWatermark,
|
| 102 | + "ImageTransition": ImageTransition, |
64 | 103 | }
|
65 | 104 |
|
66 | 105 | NODE_DISPLAY_NAME_MAPPINGS = {
|
67 | 106 | # Image
|
68 | 107 | "ImageCompositeWatermark": "Image Composite Watermark",
|
| 108 | + "ImageTransition": "Image Transition", |
69 | 109 | }
|
0 commit comments