mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-06-26 09:49:26 +08:00
feat: add ImageGridSlice node
Slices an image into a rows x columns grid (max 16x16), returning all tiles as a single IMAGE batch in row-major order. Uses uniform floor- sized cells so tiles stack into one tensor.
This commit is contained in:
parent
4e1f7cb1db
commit
15df9f2148
@ -1240,6 +1240,54 @@ class SaveImageAdvanced(IO.ComfyNode):
|
|||||||
return IO.NodeOutput(ui={"images": results})
|
return IO.NodeOutput(ui={"images": results})
|
||||||
|
|
||||||
|
|
||||||
|
class ImageGridSlice(IO.ComfyNode):
|
||||||
|
MAX_ROWS = 16
|
||||||
|
MAX_COLUMNS = 16
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def define_schema(cls):
|
||||||
|
return IO.Schema(
|
||||||
|
node_id="ImageGridSlice",
|
||||||
|
display_name="Image Grid Slice",
|
||||||
|
category="image/transform",
|
||||||
|
search_aliases=["grid", "slice image", "split image", "crop grid"],
|
||||||
|
description="Slices an image into a grid of rows x columns tiles, returned as a single batch (row-major).",
|
||||||
|
inputs=[
|
||||||
|
IO.Image.Input("image"),
|
||||||
|
IO.Int.Input("rows", default=2, min=1, max=cls.MAX_ROWS),
|
||||||
|
IO.Int.Input("columns", default=2, min=1, max=cls.MAX_COLUMNS),
|
||||||
|
],
|
||||||
|
outputs=[
|
||||||
|
IO.Image.Output(display_name="images"),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def execute(cls, image, rows, columns) -> IO.NodeOutput:
|
||||||
|
rows = max(1, min(rows, cls.MAX_ROWS))
|
||||||
|
columns = max(1, min(columns, cls.MAX_COLUMNS))
|
||||||
|
|
||||||
|
_, height, width, _ = image.shape
|
||||||
|
tile_height = height // rows
|
||||||
|
tile_width = width // columns
|
||||||
|
|
||||||
|
tiles = []
|
||||||
|
for row in range(rows):
|
||||||
|
y_start = row * tile_height
|
||||||
|
for col in range(columns):
|
||||||
|
x_start = col * tile_width
|
||||||
|
tiles.append(
|
||||||
|
image[
|
||||||
|
:,
|
||||||
|
y_start:y_start + tile_height,
|
||||||
|
x_start:x_start + tile_width,
|
||||||
|
:,
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
return IO.NodeOutput(torch.cat(tiles, dim=0))
|
||||||
|
|
||||||
|
|
||||||
class ImagesExtension(ComfyExtension):
|
class ImagesExtension(ComfyExtension):
|
||||||
@override
|
@override
|
||||||
async def get_node_list(self) -> list[type[IO.ComfyNode]]:
|
async def get_node_list(self) -> list[type[IO.ComfyNode]]:
|
||||||
@ -1262,6 +1310,7 @@ class ImagesExtension(ComfyExtension):
|
|||||||
ImageScaleToMaxDimension,
|
ImageScaleToMaxDimension,
|
||||||
SplitImageToTileList,
|
SplitImageToTileList,
|
||||||
ImageMergeTileList,
|
ImageMergeTileList,
|
||||||
|
ImageGridSlice,
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user