fix: support batch broadcasting in JoinImageWithAlpha node#13309
fix: support batch broadcasting in JoinImageWithAlpha node#13309Abdulrehman-PIAIC80387 wants to merge 1 commit intoComfy-Org:masterfrom
Conversation
…#12580) The node used min(len(image), len(alpha)) as batch size, so passing a batch of images with a single alpha mask only returned 1 image. Changed to max() with modulo indexing to broadcast the shorter input, matching the behavior of other compositing nodes like ImageCompositeMasked. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
📝 WalkthroughWalkthroughThe 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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.
🧹 Nitpick comments (1)
comfy_extras/nodes_compositing.py (1)
205-210: Lock in the new broadcast behavior with a regression test.This changes
JoinImageWithAlphafrom overlap-only batching to broadcast batching, so please add or update coverage for bothN images + 1 maskand1 image + N masks.tests-unit/comfy_extras_test/image_stitch_test.py:27-47already shows the repo’s “larger batch wins” pattern for similar image ops.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@comfy_extras/nodes_compositing.py` around lines 205 - 210, JoinImageWithAlpha now broadcasts batches (larger batch wins) so add a regression test that asserts both broadcast cases: (a) N images + 1 mask and (b) 1 image + N masks produce outputs with batch size equal to max(N_images, N_masks) and that the per-item alpha channel matches the expected broadcasted mask values; locate the operator under test (JoinImageWithAlpha in nodes_compositing.py, which uses resize_mask and concatenates alpha) and follow the existing "larger batch wins" pattern from the repo’s image-stitch tests to create two unit tests that construct small synthetic tensors, run the operator, and assert output shape and channel content for both scenarios.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@comfy_extras/nodes_compositing.py`:
- Around line 205-210: JoinImageWithAlpha now broadcasts batches (larger batch
wins) so add a regression test that asserts both broadcast cases: (a) N images +
1 mask and (b) 1 image + N masks produce outputs with batch size equal to
max(N_images, N_masks) and that the per-item alpha channel matches the expected
broadcasted mask values; locate the operator under test (JoinImageWithAlpha in
nodes_compositing.py, which uses resize_mask and concatenates alpha) and follow
the existing "larger batch wins" pattern from the repo’s image-stitch tests to
create two unit tests that construct small synthetic tensors, run the operator,
and assert output shape and channel content for both scenarios.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 18ced04d-feb6-46ff-9ad5-728129bdea09
📒 Files selected for processing (1)
comfy_extras/nodes_compositing.py
Summary
Fixes #12580
Problem
The
Join Image with Alphanode only returns a single image when given a batch of images with a single alpha mask.Root cause: In
comfy_extras/nodes_compositing.pyline 205, the batch size was calculated usingmin(len(image), len(alpha)). When a user passes a batch of 4 images with a single alpha mask,min(4, 1) = 1, so only one image is produced.This is inconsistent with every other compositing node in ComfyUI (e.g.,
ImageCompositeMasked), which correctly broadcasts the shorter input to match the longer one.Fix
Changed
comfy_extras/nodes_compositing.pyto usemax()instead ofmin()for batch size, with modulo indexing (i % len(...)) to repeat the shorter input:This handles all cases correctly: