This commit is contained in:
LEv145
2023-04-05 00:20:20 +02:00
parent 75db834e18
commit 66651c816a
13 changed files with 1902 additions and 0 deletions
+160
View File
@@ -0,0 +1,160 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
.pybuilder/
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock
# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
# pytype static type analyzer
.pytype/
# Cython debug symbols
cython_debug/
# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
+23
View File
@@ -0,0 +1,23 @@
# XYPlot: 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)
## 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
```
+8
View File
@@ -0,0 +1,8 @@
from .src import ImageSetAreaNode, FloatImageCombineNode, XYPlotNode
NODE_CLASS_MAPPINGS = {
"ImageSetArea": ImageSetAreaNode,
"FloatImageCombine": FloatImageCombineNode,
"XYPlot": XYPlotNode,
}
+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
+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]
+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
Binary file not shown.

After

Width:  |  Height:  |  Size: 210 KiB

+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
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 178 KiB