Nodes/ComfyUI_Fill-Nodes/FL Image Replace
ComfyUI Node

FL Image Replace

Swap one image in a batch without rebuilding the whole batch

By filliptm·Created 3 years ago·Updated 2 days ago· 632
FL Image Replace
  • images
  • replacement
  • masks
  • replacement_mask
  • images
  • masks
index0
show_previewfalse

Say you batch-generated 20 frames and frame 14 came back wrong - a glitch, a bad seed, a face that didn't land. Regenerating the whole batch to fix one frame is wasteful. FL_ImageReplace does the surgical version: swap exactly one image at a known index for a replacement, and everything else in the batch passes through untouched.

How it works

It takes your batch, your replacement image, and an index, and substitutes the replacement into that position. It handles the fiddly parts for you: if the replacement image has a different channel count than the batch (RGB vs RGBA mismatch), it reconciles that; negative indices work Python-style (-1 for the last image); and an out-of-range index gets clamped rather than erroring outright. There's also mask support layered on top - if you're replacing a region rather than a whole frame conceptually, you can pass masks through alongside the images.

The inputs and outputs that matter

Required: images (the batch), replacement (the new image), index (-100 to 9999, default 0 - which position to replace; negative counts from the end), and show_preview (BOOLEAN) - toggle a preview of the result directly on the node, handy for confirming you replaced the frame you meant to before continuing the pipeline.

Optional: masks (the batch's existing masks, if you have them) and replacement_mask (a mask for the new image) - wire these if mask data needs to travel alongside the swapped image rather than getting dropped.

Outputs: images (the batch with the swap applied) and masks (the corresponding mask batch, updated at that same index if you supplied mask inputs). This is also marked an output node, so its preview surfaces directly without a separate Preview Image node.

How to install it

Part of the ComfyUI_Fill-Nodes pack. ComfyUI Manager: search ComfyUI_Fill-Nodes, install, restart. Manual:

cd ComfyUI/custom_nodes
git clone https://github.com/filliptm/ComfyUI_Fill-Nodes

then restart. Tensor indexing and compositing - no external dependencies.

Common issues & troubleshooting

Double-check index against your batch's actual order before wiring this into a bigger pipeline. It's easy to assume frame indices match a video's visual order 1:1, but if anything upstream reordered, filtered, or dropped frames, "frame 14" in your head and index 14 in the tensor can drift apart. show_preview exists exactly to catch this - leave it on the first time you use this node in a new graph.

Out-of-range indices get clamped, not rejected. Ask for index 500 on a 20-image batch and you won't get an error - you'll silently get the last valid index instead. That's forgiving, but it also means a typo in the index value fails quietly rather than loudly; worth a sanity check if a replace doesn't seem to have landed where expected.

Channel mismatches are handled, but verify the visual result anyway. The node reconciles RGB/RGBA differences automatically so a replace doesn't hard-crash on a channel mismatch, but automatic reconciliation (typically dropping or adding an alpha channel) isn't the same as guaranteeing the visual result is what you wanted - check the preview, especially if your replacement came from a different source (a screenshot, a different generation pipeline) than the rest of the batch.

Masks are optional and independent of the image swap. You can replace an image without touching masks at all - the masks/replacement_mask inputs are there for when you specifically need mask data to travel with the swap, not a required part of the operation.

Category🏵️Fill Nodes/Image

Inputs (6)

NameTypeDefaultDescription
imagesIMAGE
replacementIMAGE
indexINT0-100–9999
show_previewBOOLEANfalse
masksoptMASK
replacement_maskoptMASK

Outputs (2)

NameTypeDescription
imagesIMAGE
masksMASK