Add SplitImageToTileList and ImageMergeTileList nodes.#12599
Add SplitImageToTileList and ImageMergeTileList nodes.#12599comfyanonymous merged 1 commit intomasterfrom
Conversation
With these you can split an image into tiles, do operations and then combine it back to a single image.
📝 WalkthroughWalkthroughThis pull request adds two new image processing nodes to the ComfyUI image utilities. The first node, SplitImageToTileList, divides an input image into a list of tiles using configurable width, height, and overlap parameters. The second node, ImageMergeTileList, reconstructs a single image from a tile list with specified dimensions and overlap handling. Both nodes share grid coordinate generation logic and implement per-tile weighting using sine-based masks for blending. The math module is imported to support the weighting calculations. The updated node registry exposes both new nodes publicly. 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@comfy_extras/nodes_images.py`:
- Around line 735-737: In execute (and before calling get_grid_coords) validate
that overlap is strictly less than both tile_width and tile_height (or clamp it
to a safe value like min(tile_dim-1, overlap)); if invalid, raise a clear
ValueError mentioning tile_width/tile_height and overlap to fail fast, or
silently clamp overlap to a computed safe stride and document that
behavior—update the execute signature logic around image, tile_width,
tile_height, overlap to perform this check and then call get_grid_coords with
the validated/clamped overlap.
- Around line 796-808: The code currently reads image_list[0] unsafely and can
silently produce black regions when tiles are missing or mismatched; update the
execute method to validate inputs: first assert image_list is non-empty and
raise a clear ValueError if empty, then read first_tile = image_list[0] and
capture its shape/device/dtype, call cls.get_grid_coords(w,h,t_w,t_h,ovlp) as
now, and then verify len(image_list) == len(coords) raising a descriptive error
if not; also iterate the tiles in image_list and validate each has the same
batch/channel dims, identical t_h/t_w (or compatible), device and dtype as
first_tile and raise a ValueError listing the offending index(s) if any mismatch
is found so the method fails fast instead of producing silent corruption.
| def execute(cls, image, tile_width, tile_height, overlap): | ||
| b, h, w, c = image.shape | ||
| coords = cls.get_grid_coords(w, h, tile_width, tile_height, overlap) |
There was a problem hiding this comment.
Validate overlap against tile size to prevent runaway tiling.
When overlap >= tile_width/height, stride collapses to 1, exploding tile counts (e.g., tile_width=64 with default overlap=128). Add a guard to fail fast or clamp.
🛡️ Proposed guard
`@classmethod`
def execute(cls, image, tile_width, tile_height, overlap):
+ if overlap >= tile_width or overlap >= tile_height:
+ raise ValueError("overlap must be smaller than tile_width and tile_height")
b, h, w, c = image.shape
coords = cls.get_grid_coords(w, h, tile_width, tile_height, overlap)🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@comfy_extras/nodes_images.py` around lines 735 - 737, In execute (and before
calling get_grid_coords) validate that overlap is strictly less than both
tile_width and tile_height (or clamp it to a safe value like min(tile_dim-1,
overlap)); if invalid, raise a clear ValueError mentioning
tile_width/tile_height and overlap to fail fast, or silently clamp overlap to a
computed safe stride and document that behavior—update the execute signature
logic around image, tile_width, tile_height, overlap to perform this check and
then call get_grid_coords with the validated/clamped overlap.
| def execute(cls, image_list, final_width, final_height, overlap): | ||
| w = final_width[0] | ||
| h = final_height[0] | ||
| ovlp = overlap[0] | ||
| feather_str = 1.0 | ||
|
|
||
| first_tile = image_list[0] | ||
| b, t_h, t_w, c = first_tile.shape | ||
| device = first_tile.device | ||
| dtype = first_tile.dtype | ||
|
|
||
| coords = cls.get_grid_coords(w, h, t_w, t_h, ovlp) | ||
|
|
There was a problem hiding this comment.
Fail fast on empty or mismatched tile lists.
image_list[0] will throw on empty input, and mismatched counts silently create black regions. Add validation to avoid silent corruption.
🧪 Suggested validation
`@classmethod`
def execute(cls, image_list, final_width, final_height, overlap):
+ if not image_list:
+ raise ValueError("image_list is empty")
w = final_width[0]
h = final_height[0]
ovlp = overlap[0]
feather_str = 1.0
@@
coords = cls.get_grid_coords(w, h, t_w, t_h, ovlp)
+ if len(image_list) != len(coords):
+ raise ValueError(f"Expected {len(coords)} tiles, got {len(image_list)}")🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@comfy_extras/nodes_images.py` around lines 796 - 808, The code currently
reads image_list[0] unsafely and can silently produce black regions when tiles
are missing or mismatched; update the execute method to validate inputs: first
assert image_list is non-empty and raise a clear ValueError if empty, then read
first_tile = image_list[0] and capture its shape/device/dtype, call
cls.get_grid_coords(w,h,t_w,t_h,ovlp) as now, and then verify len(image_list) ==
len(coords) raising a descriptive error if not; also iterate the tiles in
image_list and validate each has the same batch/channel dims, identical t_h/t_w
(or compatible), device and dtype as first_tile and raise a ValueError listing
the offending index(s) if any mismatch is found so the method fails fast instead
of producing silent corruption.
With these you can split an image into tiles, do operations and then combine it back to a single image.