Nodes/ꘇ Genereti/ꘇ top.math
ComfyUI Node

ꘇ top.math

RGB arithmetic with a scalar or a second image — alpha survives

By languel·Created about a month ago·Updated 3 days ago· 1
ꘇ top.math
  • image
  • operand
  • image
◄operation▾►
◄value1.00►

ComfyUI has plenty of nodes that do something to an image; it has surprisingly few that do plain arithmetic between things. top.math is that: seven operations on the RGB channels, clamped to 0..1, with A's alpha handed through untouched. If you've been reaching for a mask-combine node, a brightness multiply, or a "what changed between these two frames" pass, this is one node instead of three.

It's a small piece of the deterministic pixel-ops layer - the stuff the KB describes as settled and unglamorous, where the real problem is picking the right primitive rather than finding a clever one. Multiply, minimum and maximum look interchangeable until you use the wrong one and your soft mask turns into a hard hole.

How it works

You give it image (A), an operation, and either a scalar value or a second operand IMAGE. The supported operations are multiply, add, subtract, divide, difference, minimum, maximum. RGB results clamp to 0..1; alpha is copied straight from A. Divide guards against zero (it substitutes a tiny epsilon instead of producing inf), so a division by a black map won't poison the graph with NaNs.

Which operation you actually want:

  • multiply - dim/brighten by a constant, or mask A softly by B. image × image is a crude contrast curve.
  • minimum / maximum - the mask-combine pair. Minimum of two soft masks is their intersection (the darker value wins); maximum is their union. Multiply also fades, but it darkens at the overlap, which is usually not what you meant.
  • difference - absolute difference. Two consecutive video frames through difference is a motion/change matte for free.
  • subtract / divide - order-sensitive and sign-hostile: negatives clamp to zero, so subtract clips instead of going negative.
  • add - accumulate light. Pairs nicely with top.composite's add/screen when you're stacking passes.

The inputs that matter

  • image - the left operand. Its alpha is the alpha you get out.
  • operation - see above.
  • value - the scalar right operand, used only when nothing is wired to operand.
  • operand - optional IMAGE that replaces the scalar entirely. Tooltip wording is the author's: "Scalar operand when no second image is connected; alpha is preserved."

One output, image. Feed it into top.mask if you built a soft matte and want it applied, or into top.displace if you built a displacement map.

Install

ComfyUI Manager → search ꘇ Genereti → install, or:

git clone https://github.com/languel/genereti.git custom_nodes/genereti
./.venv/bin/python -m pip install -r custom_nodes/genereti/requirements.txt

Restart and refresh the page. The only dependency is comfyui-frontend-package>=1.53.6, which you need because the pack uses the newer node schema API; torch and NumPy come from your ComfyUI install. No checkpoints, no downloads. Nodes show up as ꘇ top.math in the Genereti / TOP category - the leader glyph sorts weirdly, so search genereti rather than browsing.

Traps

Everything clamps at 0..1. There's no HDR headroom, so a divide-then-multiply chain that would work in a compositor will crush here. Do brightness work in top.level, which has gamma, instead of chaining multiplies.

Batches must line up. B can be a single image (it broadcasts) or a batch matching A. Anything else is an error, not a warning.

Live and Queue disagree slightly. These nodes run twice: WebGPU in live mode, PyTorch on Queue. Live intermediate textures are 8-bit, Queue keeps floats, so don't chase a one-level difference between the live preview and the saved file.

The pack is early alpha - the README asks you to back up workflows before updating. Heed that.

CategoryGenereti / TOP

Inputs (4)

NameTypeDefaultDescription
imageIMAGE—
operationCOMBO7 options: multiply, add, subtract, divide, difference, minimum, +1
valueFLOAT1.00-4–4Scalar operand when no second image is connected; alpha is preserved.
operandoptIMAGE—

Outputs (1)

NameTypeDescription
imageIMAGE—