Author SHA1 Message Date
LEv145 9963935c26 v 2.1.0
Add `ImageCombineNode`
Add `ImagesGridByColumnsNode`
Add `ImagesGridByRowsNode`
Add `create_image_grid_by_rows` util
Add `create_image_grid_by_columns` util
Add `create_image_grid` util
Refactor code
Update workflows
Update images
Update link in README.md
Rename project
2023-04-05 22:45:26 +02:00
LEv145 2059c14cff v 2.0.1
Remove old files
Fix `create_image_grid`
2023-04-05 19:34:54 +02:00
18 changed files with 868 additions and 1168 deletions
+7 -7
View File
@@ -1,10 +1,10 @@
# XYPlot: Comfy plugin
# ImagesGrid: Comfy plugin
![Image](./workflows/xy_plot_mini.png)
[Workflows](./workflows/xy_plot_mini.json)
![Image](./workflows/xy_plot_base.png)
[Workflows](./workflows/xy_plot_base.json)
![Image](./workflows/mini.png)
[Workflows](./workflows/mini.json)
![Image](./workflows/base.png)
[Workflows](./workflows/base.json)
## How to use
@@ -13,11 +13,11 @@
```
cd custom_nodes # From comfy path
git clone https://github.com/LEv145/XY-plot-comfy-plugin XYPlot
git clone https://github.com/LEv145/images-grid-comfy-plugin ImagesGrid
```
### Update
```
cd custom_nodes/XYPlot
cd custom_nodes/ImagesGrid
git pull
```
+4 -2
View File
@@ -1,7 +1,9 @@
from .src import LatentCombineNode, XYPlotNode
from .src import LatentCombineNode, ImagesGridByColumnsNode, ImagesGridByRowsNode, ImageCombineNode
NODE_CLASS_MAPPINGS = {
"XYPlot": XYPlotNode,
"LatentCombine": LatentCombineNode,
"ImagesGridByColumns": ImagesGridByColumnsNode,
"ImagesGridByRows": ImagesGridByRowsNode,
"ImageCombine": ImageCombineNode,
}
+2 -1
View File
@@ -1,2 +1,3 @@
from .nodes.xy_plot import XYPlotNode
from .nodes.images_grid import ImagesGridByColumnsNode, ImagesGridByRowsNode
from .nodes.latent_combine import LatentCombineNode
from .nodes.image_combine import ImageCombineNode
+2 -9
View File
@@ -1,16 +1,9 @@
import typing as t
from dataclasses import dataclass
class BasePlotNode():
CATEGORY: str = "XYPlot"
class BaseNode():
CATEGORY: str = "ImagesGrid"
FUNCTION: str = "execute"
@dataclass
class KSamplerXYPlotInput():
setting: str
value: int
Image = t.Any
-23
View File
@@ -1,23 +0,0 @@
import typing as t
from ..base import BasePlotNode, Image
class FloatImageCombineNode(BasePlotNode):
RETURN_TYPES: t.Tuple[str] = ("IMAGES",)
@classmethod
def INPUT_TYPES(cls) -> t.Dict[str, t.Any]:
return {
"required": {
"float_image_1": ("IMAGES",),
"float_image_2": ("IMAGES",),
},
}
def execute(
self,
float_image_1: t.List[Image],
float_image_2: t.List[Image],
) -> t.Tuple[t.List[Image]]:
return (float_image_1 + float_image_2,)
+32
View File
@@ -0,0 +1,32 @@
import typing as t
import torch
from ..base import BaseNode, Image
class ImageCombineNode(BaseNode):
RETURN_TYPES: t.Tuple[str] = ("IMAGE",)
@classmethod
def INPUT_TYPES(cls) -> t.Dict[str, t.Any]:
return {
"required": {
"image_1": ("IMAGE",),
"image_2": ("IMAGE",),
},
}
def execute(
self,
image_1: Image,
image_2: Image,
) -> t.Tuple[Image]:
print(image_1.size())
print(image_2.size())
print(image_1)
result = torch.cat((image_1, image_2), 0)
print(result.size())
return (result,)
-18
View File
@@ -1,18 +0,0 @@
import typing as t
from ..base import BasePlotNode, Image
class ImageSetAreaNode(BasePlotNode):
RETURN_TYPES: t.Tuple[str] = ("IMAGES",)
@classmethod
def INPUT_TYPES(cls) -> t.Dict[str, t.Any]:
return {
"required": {
"image": ("IMAGE",),
},
}
def execute(self, image: Image) -> t.Tuple[t.List[Image]]:
return ([image],)
+48
View File
@@ -0,0 +1,48 @@
import typing as t
from ..base import BaseNode, Image
from ..utils import (
tensor_to_pillow,
pillow_to_tensor,
create_image_grid_by_columns,
create_image_grid_by_rows,
)
class BaseImagesGridNode(BaseNode):
RETURN_TYPES: t.Tuple[str] = ("IMAGE",)
@classmethod
def _create_input_types(cls, coordinate_name: str) -> t.Dict[str, t.Any]:
return {
"required": {
"images": ("IMAGE",),
"gap": ("INT", {"default": 0, "min": 0}),
coordinate_name: ("INT", {"default": 1, "min": 1}),
}
}
def _create_execute(self, images, function, function_kw) -> t.Tuple[Image]:
pillow_images = [tensor_to_pillow(i) for i in images]
pillow_grid = function(images=pillow_images, **function_kw)
tensor_grid = pillow_to_tensor(pillow_grid)
return (tensor_grid,)
class ImagesGridByColumnsNode(BaseImagesGridNode):
@classmethod
def INPUT_TYPES(cls) -> t.Dict[str, t.Any]:
return cls._create_input_types("max_columns")
def execute(self, images: Image, **kw) -> tuple[Image]:
return self._create_execute(images, create_image_grid_by_columns, kw)
class ImagesGridByRowsNode(BaseImagesGridNode):
@classmethod
def INPUT_TYPES(cls) -> t.Dict[str, t.Any]:
return cls._create_input_types("max_rows")
def execute(self, images: Image, **kw) -> tuple[Image]:
return self._create_execute(images, create_image_grid_by_rows, kw)
-62
View File
@@ -1,62 +0,0 @@
import typing as t
from nodes import KSamplerAdvanced # type: ignore
from ..base import BasePlotNode, Image, KSamplerXYPlotInput
class KSamplerXYPlotNode(BasePlotNode):
RETURN_TYPES: t.Tuple[str] = ("IMAGES",)
def __init__(self) -> None:
self._sampler = KSamplerAdvanced()
@classmethod
def INPUT_TYPES(cls):
result = KSamplerAdvanced.INPUT_TYPES()
result["required"]["vae"] = ("VAE", )
#result["required"]["x_items"] = ("XYPlotItem",)
#result["required"]["y_items"] = ("XYPlotItem",)
return result
def execute(
self,
vae,
#x_items,
#y_items,
**sampler_kw,
) -> tuple[t.List[Image]]:
x_items = [
KSamplerXYPlotInput(value=1, setting="cfg"),
KSamplerXYPlotInput(value=2, setting="cfg"),
]
y_items = [
KSamplerXYPlotInput(value=1, setting="noise_seed"),
KSamplerXYPlotInput(value=2, setting="noise_seed"),
]
latents = self._sample_latents(
x_items=x_items,
y_items=y_items,
sampler_kw=sampler_kw,
)
result = list(self._decode_latents(latents=latents, vae=vae))
print(result)
print(type(result[0]))
return (result,)
def _sample_latents(self, x_items, y_items, sampler_kw):
for x in x_items:
for y in y_items:
sampler_settings = sampler_kw.copy()
sampler_settings[x.setting] = x.value
sampler_settings[y.setting] = y.value
yield self._sampler.sample(**sampler_settings)[0]
def _decode_latents(self, latents, vae) -> t.Iterable[Image]:
return (
vae.decode(i["samples"])
for i in latents
)
+3 -5
View File
@@ -2,10 +2,10 @@ import typing as t
import torch
from ..base import BasePlotNode, Image
from ..base import BaseNode, Image
class LatentCombineNode(BasePlotNode):
class LatentCombineNode(BaseNode):
RETURN_TYPES: t.Tuple[str] = ("LATENT",)
@classmethod
@@ -22,8 +22,6 @@ class LatentCombineNode(BasePlotNode):
latent_1: t.Dict[str, t.Any],
latent_2: t.Dict[str, t.Any],
) -> t.Tuple[t.Dict[str, t.Any]]:
latent_1_samples = latent_1["samples"]
latent_2_samples = latent_2["samples"]
samples = torch.cat((latent_1_samples, latent_2_samples), 0)
samples = torch.cat((latent_1["samples"], latent_2["samples"]), 0)
return ({"samples": samples},)
-30
View File
@@ -1,30 +0,0 @@
import typing as t
from ..base import BasePlotNode, 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": {
"images": ("IMAGE",),
"gap": ("INT", {"default": 0, "min": 0}),
"nrow": ("INT", {"default": 1, "min": 1}),
},
}
def execute(
self,
images: Image,
nrow: int,
gap: int
) -> tuple[Image]:
pillow_images = [tensor_to_pillow(i) for i in images]
pillow_grid = create_image_grid(pillow_images, nrow=nrow, gap=gap)
tensor_grid = pillow_to_tensor(pillow_grid)
return (tensor_grid,)
+27 -13
View File
@@ -13,27 +13,41 @@ def pillow_to_tensor(image):
return torch.from_numpy(np.array(image).astype(np.float32) / 255.0).unsqueeze(0)
def create_image_grid(images: t.List[Image.Image], gap: int, ncol: int):
# Calculate the number of rows needed based on the number of images and columns
nrow = (len(images) + ncol - 1) // ncol
def create_image_grid_by_columns(
images: t.List[Image.Image],
gap: int,
max_columns: int,
) -> Image.Image:
max_rows = (len(images) + max_columns - 1) // max_columns
return create_image_grid(images=images, gap=gap, max_columns=max_columns, max_rows=max_rows)
# Get the size of the first image to use as a template for the grid
def create_image_grid_by_rows(
images: t.List[Image.Image],
gap: int,
max_rows: int,
) -> Image.Image:
max_columns = (len(images) + max_rows - 1) // max_rows
return create_image_grid(images=images, gap=gap, max_columns=max_columns, max_rows=max_rows)
def create_image_grid(
images: t.List[Image.Image],
gap: int,
max_columns: int,
max_rows: int,
) -> Image.Image:
size = images[0].size
# Calculate the total size of the grid with gaps
width = size[0] * ncol + gap * (ncol - 1)
height = size[1] * nrow + gap * (nrow - 1)
width = size[0] * max_columns + (max_columns - 1) * gap
height = size[1] * max_rows + (max_rows - 1) * gap
# Create a new image for the grid
grid_image = Image.new("RGB", (width, height), color="white")
# Iterate over each image and paste it into the grid
for i, image in enumerate(images):
# Calculate the position of the image in the grid
x = (i % ncol) * (size[0] + gap)
y = (i // ncol) * (size[1] + gap)
x = (i % max_columns) * (size[0] + gap)
y = (i // max_columns) * (size[1] + gap)
# Paste the image into the grid
grid_image.paste(image, (x, y))
return grid_image
File diff suppressed because it is too large Load Diff
Binary file not shown.

After

Width:  |  Height:  |  Size: 420 KiB

@@ -1,218 +1,7 @@
{
"last_node_id": 44,
"last_link_id": 75,
"last_node_id": 56,
"last_link_id": 97,
"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": "IMAGES",
"type": "IMAGES",
"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": "IMAGES",
"link": 12
},
{
"name": "float_image_2",
"type": "IMAGES",
"link": 13
}
],
"outputs": [
{
"name": "IMAGES",
"type": "IMAGES",
"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": "IMAGES",
"link": 32
},
{
"name": "float_image_2",
"type": "IMAGES",
"link": 22
}
],
"outputs": [
{
"name": "IMAGES",
"type": "IMAGES",
"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": "IMAGES",
"type": "IMAGES",
"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": "IMAGES",
"type": "IMAGES",
"links": [
22
],
"slot_index": 0
}
],
"properties": {
"Node name for S&R": "ImageSetArea"
}
},
{
"id": 41,
"type": "LoadImage",
@@ -232,7 +21,7 @@
"name": "IMAGE",
"type": "IMAGE",
"links": [
73
90
],
"slot_index": 0
},
@@ -250,6 +39,43 @@
"image"
]
},
{
"id": 42,
"type": "LoadImage",
"pos": [
69,
449
],
"size": {
"0": 315,
"1": 102
},
"flags": {},
"order": 1,
"mode": 0,
"outputs": [
{
"name": "IMAGE",
"type": "IMAGE",
"links": [
91
],
"slot_index": 0
},
{
"name": "MASK",
"type": "MASK",
"links": null
}
],
"properties": {
"Node name for S&R": "LoadImage"
},
"widgets_values": [
"ComfyUI_00153_.png",
"image"
]
},
{
"id": 43,
"type": "LoadImage",
@@ -269,7 +95,7 @@
"name": "IMAGE",
"type": "IMAGE",
"links": [
75
94
],
"slot_index": 0
},
@@ -288,24 +114,134 @@
]
},
{
"id": 17,
"type": "XYPlot",
"id": 54,
"type": "ImageCombine",
"pos": [
1075,
326
460,
350
],
"size": {
"0": 210,
"1": 46
},
"flags": {},
"order": 3,
"mode": 0,
"inputs": [
{
"name": "image_1",
"type": "IMAGE",
"link": 90
},
{
"name": "image_2",
"type": "IMAGE",
"link": 91
}
],
"outputs": [
{
"name": "IMAGE",
"type": "IMAGE",
"links": [
93
],
"slot_index": 0
}
],
"properties": {
"Node name for S&R": "ImageCombine"
},
"color": "#322",
"bgcolor": "#533"
},
{
"id": 55,
"type": "ImageCombine",
"pos": [
460,
440
],
"size": {
"0": 210,
"1": 46
},
"flags": {},
"order": 4,
"mode": 0,
"inputs": [
{
"name": "image_1",
"type": "IMAGE",
"link": 93
},
{
"name": "image_2",
"type": "IMAGE",
"link": 94
}
],
"outputs": [
{
"name": "IMAGE",
"type": "IMAGE",
"links": [
95
],
"slot_index": 0
}
],
"properties": {
"Node name for S&R": "ImageCombine"
},
"color": "#322",
"bgcolor": "#533"
},
{
"id": 56,
"type": "PreviewImage",
"pos": [
1059,
350
],
"size": [
428.921914672851,
507.1954368591306
],
"flags": {},
"order": 6,
"mode": 0,
"inputs": [
{
"name": "images",
"type": "IMAGE",
"link": 97
}
],
"properties": {
"Node name for S&R": "PreviewImage"
}
},
{
"id": 53,
"type": "ImagesGridByColumns",
"pos": [
700,
350
],
"size": {
"0": 315,
"1": 82
},
"flags": {},
"order": 8,
"order": 5,
"mode": 0,
"inputs": [
{
"name": "images",
"type": "IMAGES",
"link": 24
"type": "IMAGE",
"link": 95,
"slot_index": 0
}
],
"outputs": [
@@ -313,127 +249,68 @@
"name": "IMAGE",
"type": "IMAGE",
"links": [
20
97
],
"slot_index": 0
}
],
"properties": {
"Node name for S&R": "XYPlot"
"Node name for S&R": "ImagesGridByColumns"
},
"widgets_values": [
10,
5,
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"
]
"color": "#322",
"bgcolor": "#533"
}
],
"links": [
[
12,
10,
0,
12,
0,
"IMAGES"
],
[
13,
11,
0,
12,
1,
"IMAGES"
],
[
20,
17,
0,
15,
0,
"IMAGE"
],
[
22,
18,
0,
19,
1,
"IMAGES"
],
[
24,
19,
0,
17,
0,
"IMAGES"
],
[
32,
12,
0,
19,
0,
"IMAGES"
],
[
73,
90,
41,
0,
10,
54,
0,
"IMAGE"
],
[
74,
91,
42,
0,
11,
54,
1,
"IMAGE"
],
[
93,
54,
0,
55,
0,
"IMAGE"
],
[
75,
94,
43,
0,
18,
55,
1,
"IMAGE"
],
[
95,
55,
0,
53,
0,
"IMAGE"
],
[
97,
53,
0,
56,
0,
"IMAGE"
]
@@ -442,4 +319,4 @@
"config": {},
"extra": {},
"version": 0.4
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 273 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 210 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 178 KiB