This commit is contained in:
LEv145
2023-04-05 00:14:39 +02:00
commit 2875659661
19 changed files with 1743 additions and 0 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 210 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 178 KiB

+24
View File
@@ -0,0 +1,24 @@
# XYPlot: Comfy plugin
![Image](.readme/preview_mini.png)
![Image](.readme/preview_base.png)
## How to use
### Install
```
cd custom_nodes # From comfy path
git clone https://github.com/LEv145/XY-plot-comfy-plugin XYPlot
```
### Update
```
cd custom_nodes/XYPlot
git pull
```
## Workflows
[Workflows](./workflows)
+8
View File
@@ -0,0 +1,8 @@
from .src import ImageSetAreaNode, FloatImageCombineNode, XYPlotNode
NODE_CLASS_MAPPINGS = {
"ImageSetArea": ImageSetAreaNode,
"FloatImageCombine": FloatImageCombineNode,
"XYPlot": XYPlotNode,
}
Binary file not shown.
+3
View File
@@ -0,0 +1,3 @@
from .nodes.image_set_area import ImageSetAreaNode
from .nodes.float_image_combine import FloatImageCombineNode
from .nodes.xy_plot import XYPlotNode
Binary file not shown.
Binary file not shown.
Binary file not shown.
+10
View File
@@ -0,0 +1,10 @@
import typing as t
class BasePlotNode():
CATEGORY: str = "XYPlot"
FUNCTION: str = "execute"
Image = t.Any
FloatImage = list[Image]
Binary file not shown.
Binary file not shown.
+19
View File
@@ -0,0 +1,19 @@
import typing as t
from ..base import BasePlotNode, FloatImage
class FloatImageCombineNode(BasePlotNode):
RETURN_TYPES: t.Tuple[str] = ("FLOAT_IMAGE",)
@classmethod
def INPUT_TYPES(cls) -> t.Dict[str, t.Any]:
return {
"required": {
"float_image_1": ("FLOAT_IMAGE",),
"float_image_2": ("FLOAT_IMAGE",),
},
}
def execute(self, float_image_1: FloatImage, float_image_2: FloatImage) -> tuple[FloatImage]:
return (float_image_1 + float_image_2,)
+21
View File
@@ -0,0 +1,21 @@
import typing as t
from ..base import BasePlotNode, FloatImage, Image
class ImageSetAreaNode(BasePlotNode):
RETURN_TYPES: t.Tuple[str] = ("FLOAT_IMAGE",)
def __init__(self):
pass
@classmethod
def INPUT_TYPES(cls) -> t.Dict[str, t.Any]:
return {
"required": {
"image": ("IMAGE",),
},
}
def execute(self, image: Image) -> tuple[FloatImage]:
return ([image],)
+30
View File
@@ -0,0 +1,30 @@
import typing as t
from ..base import BasePlotNode, FloatImage, Image
from ..utils import tensor_to_pillow, pillow_to_tensor, create_image_grid
class XYPlotNode(BasePlotNode):
RETURN_TYPES: t.Tuple[str] = ("IMAGE",)
@classmethod
def INPUT_TYPES(cls) -> t.Dict[str, t.Any]:
return {
"required": {
"float_image": ("FLOAT_IMAGE",),
"gap": ("INT", {"default": 0, "min": 0}),
"nrow": ("INT", {"default": 1, "min": 1}),
},
}
def execute(
self,
float_image: FloatImage,
nrow: int,
gap: int
) -> tuple[Image]:
pillow_images = [tensor_to_pillow(i) for i in float_image]
pillow_grid = create_image_grid(pillow_images, nrow=nrow, gap=gap)
tensor_grid = pillow_to_tensor(pillow_grid)
return (tensor_grid,)
+47
View File
@@ -0,0 +1,47 @@
import typing as t
import torch
import numpy as np
from PIL import Image
def tensor_to_pillow(image):
return Image.fromarray(np.clip(255. * image.cpu().numpy().squeeze(), 0, 255).astype(np.uint8))
def pillow_to_tensor(image):
return torch.from_numpy(np.array(image).astype(np.float32) / 255.0).unsqueeze(0)
def create_image_grid(images, gap, nrow):
"""
Create a grid of images with a specified gap and number of rows.
Args:
images (List[PIL.Image.Image]): List of images to be placed in the grid.
gap (int, optional): Gap between images in pixels. Defaults to 10.
nrow (int, optional): Number of rows in the grid. Defaults to 3.
Returns:
PIL.Image.Image: The merged image grid.
"""
# Calculate number of columns based on number of rows and images
ncol = (len(images) + nrow - 1) // nrow
# Get size of each image in pixels
image_width, image_height = images[0].size
# Create new image to hold the grid
grid_width = ncol * image_width + (ncol - 1) * gap
grid_height = nrow * image_height + (nrow - 1) * gap
grid_image = Image.new("RGB", (grid_width, grid_height), color="white")
# Paste images into grid
for i, image in enumerate(images):
row = i // ncol
col = i % ncol
x = col * (image_width + gap)
y = row * (image_height + gap)
grid_image.paste(image, (x, y))
return grid_image
File diff suppressed because it is too large Load Diff
+445
View File
@@ -0,0 +1,445 @@
{
"last_node_id": 44,
"last_link_id": 75,
"nodes": [
{
"id": 15,
"type": "PreviewImage",
"pos": [
1435,
325
],
"size": {
"0": 363.55511474609375,
"1": 290.6986999511719
},
"flags": {},
"order": 9,
"mode": 0,
"inputs": [
{
"name": "images",
"type": "IMAGE",
"link": 20
}
],
"properties": {
"Node name for S&R": "PreviewImage"
}
},
{
"id": 10,
"type": "ImageSetArea",
"pos": [
437,
307
],
"size": {
"0": 216.59999084472656,
"1": 26
},
"flags": {},
"order": 3,
"mode": 0,
"inputs": [
{
"name": "image",
"type": "IMAGE",
"link": 73
}
],
"outputs": [
{
"name": "FLOAT_IMAGE",
"type": "FLOAT_IMAGE",
"links": [
12
],
"slot_index": 0
}
],
"properties": {
"Node name for S&R": "ImageSetArea"
}
},
{
"id": 12,
"type": "FloatImageCombine",
"pos": [
711,
301
],
"size": {
"0": 317.4000244140625,
"1": 46
},
"flags": {},
"order": 6,
"mode": 0,
"inputs": [
{
"name": "float_image_1",
"type": "FLOAT_IMAGE",
"link": 12
},
{
"name": "float_image_2",
"type": "FLOAT_IMAGE",
"link": 13
}
],
"outputs": [
{
"name": "FLOAT_IMAGE",
"type": "FLOAT_IMAGE",
"links": [
32
],
"slot_index": 0
}
],
"properties": {
"Node name for S&R": "FloatImageCombine"
}
},
{
"id": 19,
"type": "FloatImageCombine",
"pos": [
712,
387
],
"size": {
"0": 317.4000244140625,
"1": 46
},
"flags": {},
"order": 7,
"mode": 0,
"inputs": [
{
"name": "float_image_1",
"type": "FLOAT_IMAGE",
"link": 32
},
{
"name": "float_image_2",
"type": "FLOAT_IMAGE",
"link": 22
}
],
"outputs": [
{
"name": "FLOAT_IMAGE",
"type": "FLOAT_IMAGE",
"links": [
24
],
"slot_index": 0
}
],
"properties": {
"Node name for S&R": "FloatImageCombine"
}
},
{
"id": 11,
"type": "ImageSetArea",
"pos": [
441,
372
],
"size": {
"0": 216.59999084472656,
"1": 26
},
"flags": {},
"order": 4,
"mode": 0,
"inputs": [
{
"name": "image",
"type": "IMAGE",
"link": 74,
"slot_index": 0
}
],
"outputs": [
{
"name": "FLOAT_IMAGE",
"type": "FLOAT_IMAGE",
"links": [
13
],
"slot_index": 0
}
],
"properties": {
"Node name for S&R": "ImageSetArea"
}
},
{
"id": 18,
"type": "ImageSetArea",
"pos": [
439,
439
],
"size": {
"0": 216.59999084472656,
"1": 26
},
"flags": {},
"order": 5,
"mode": 0,
"inputs": [
{
"name": "image",
"type": "IMAGE",
"link": 75
}
],
"outputs": [
{
"name": "FLOAT_IMAGE",
"type": "FLOAT_IMAGE",
"links": [
22
],
"slot_index": 0
}
],
"properties": {
"Node name for S&R": "ImageSetArea"
}
},
{
"id": 41,
"type": "LoadImage",
"pos": [
69,
307
],
"size": {
"0": 315,
"1": 102
},
"flags": {},
"order": 0,
"mode": 0,
"outputs": [
{
"name": "IMAGE",
"type": "IMAGE",
"links": [
73
],
"slot_index": 0
},
{
"name": "MASK",
"type": "MASK",
"links": null
}
],
"properties": {
"Node name for S&R": "LoadImage"
},
"widgets_values": [
"ComfyUI_00171_.png",
"image"
]
},
{
"id": 43,
"type": "LoadImage",
"pos": [
68,
592
],
"size": {
"0": 315,
"1": 102
},
"flags": {},
"order": 2,
"mode": 0,
"outputs": [
{
"name": "IMAGE",
"type": "IMAGE",
"links": [
75
],
"slot_index": 0
},
{
"name": "MASK",
"type": "MASK",
"links": null
}
],
"properties": {
"Node name for S&R": "LoadImage"
},
"widgets_values": [
"ComfyUI_00116_.png",
"image"
]
},
{
"id": 17,
"type": "XYPlot",
"pos": [
1075,
326
],
"size": {
"0": 315,
"1": 82
},
"flags": {},
"order": 8,
"mode": 0,
"inputs": [
{
"name": "float_image",
"type": "FLOAT_IMAGE",
"link": 24
}
],
"outputs": [
{
"name": "IMAGE",
"type": "IMAGE",
"links": [
20
],
"slot_index": 0
}
],
"properties": {
"Node name for S&R": "XYPlot"
},
"widgets_values": [
10,
2
]
},
{
"id": 42,
"type": "LoadImage",
"pos": [
69,
449
],
"size": {
"0": 315,
"1": 102
},
"flags": {},
"order": 1,
"mode": 0,
"outputs": [
{
"name": "IMAGE",
"type": "IMAGE",
"links": [
74
],
"slot_index": 0
},
{
"name": "MASK",
"type": "MASK",
"links": null
}
],
"properties": {
"Node name for S&R": "LoadImage"
},
"widgets_values": [
"ComfyUI_00153_.png",
"image"
]
}
],
"links": [
[
12,
10,
0,
12,
0,
"FLOAT_IMAGE"
],
[
13,
11,
0,
12,
1,
"FLOAT_IMAGE"
],
[
20,
17,
0,
15,
0,
"IMAGE"
],
[
22,
18,
0,
19,
1,
"FLOAT_IMAGE"
],
[
24,
19,
0,
17,
0,
"FLOAT_IMAGE"
],
[
32,
12,
0,
19,
0,
"FLOAT_IMAGE"
],
[
73,
41,
0,
10,
0,
"IMAGE"
],
[
74,
42,
0,
11,
0,
"IMAGE"
],
[
75,
43,
0,
18,
0,
"IMAGE"
]
],
"groups": [],
"config": {},
"extra": {},
"version": 0.4
}