Nodes/ComfyUI-Przewodo-Utils/Swap Two Images in a comparison
ComfyUI Node

Swap Two Images in a comparison

Typed routing for the two-frame decision

By przewodo·Created about a year ago·Updated 4 months ago· 4
Swap Two Images in a comparison
  • value_a
  • value_b
  • input_a
  • input_b
  • input_a
  • input_b
comparisona == b

Same idea as SwapAnyComparison, but with the sockets disciplined: the payload is always IMAGE, so your wires can't drift into type confusion. You compare two condition values with any of the six operators, and based on the result, two images either swap places on their way out or pass through in order.

The concrete use case is the one that justifies a typed variant: video and image-to-video workflows where you have two reference frames - a start image and an end image, say - and you want them to trade roles depending on a condition like a frame count or a mode selection. When both sockets are IMAGE, the graph is self-documenting: you can't accidentally route a string into a frame slot and discover the mistake two nodes downstream.

How it works

Structurally it's identical to its any-type sibling:

  • value_a / value_b - the condition operands (any type), tested with the comparison operator.
  • input_a / input_b - the two IMAGE payloads.

If the comparison is true, the outputs cross: input_a output carries image B, input_b output carries image A. If false, straight through. The condition values and the images are fully separate - you could compare two frame counts while routing two unrelated images, or compare the images themselves by their numeric properties if you feed numbers in.

The difference that matters: input_a and input_b here are declared as IMAGE (with the outputs typed IMAGE too), so ComfyUI's type checker keeps the payload side honest. The condition side stays *, because conditions can be numbers, strings, anything.

The inputs that matter

  • value_a / value_b - the comparison operands.
  • comparison - the operator, six options.
  • input_a / input_b - the two images to swap.

Outputs: input_a and input_b, IMAGE-typed, swapped or not.

Installing it

Part of ComfyUI-Przewodo-Utils. ComfyUI Manager → search the pack, or:

cd ComfyUI/custom_nodes
git clone https://github.com/przewodo/ComfyUI-Przewodo-Utils.git

Restart. No extra dependencies.

Where people get tripped up

The recurring theme of this pack's swap family: the condition values aren't the images. People wire two images into value_a/value_b expecting an image comparison, then get confused when the comparison just checks identity/equality on tensors. If you genuinely want to compare the images (pixel similarity, size, whatever), you need a comparison node upstream producing a number or boolean, and those become your value_* inputs. This node's job is routing, not judging images.

And a scope note: if you don't need the comparison at all - just "swap these two frames when a boolean is set" - this pack's SwapAnyCondition is the lighter tool, and it'll happily carry images too. The comparison-driven variant earns its place when the swap decision has real logic behind it and you want the graph to state that logic in one place.

CategoryPrzewodoUtils

Inputs (5)

NameTypeDefaultDescription
value_a*First value for comparison operation. Used as left operand in the comparison
value_b*Second value for comparison operation. Used as right operand in the comparison
comparisonCOMBOa == bComparison operation to evaluate between value_a and value_b. If true, image inputs are swapped
input_aoptIMAGEFirst image input to swap. Will be returned as 'input_b' if comparison is true, otherwise as 'input_a'
input_boptIMAGESecond image input to swap. Will be returned as 'input_a' if comparison is true, otherwise as 'input_b'

Outputs (2)

NameTypeDescription
input_aIMAGE
input_bIMAGE