ComfyUI Node

Divided

Divide two images and pray nothing's zero — the risky sibling of Multiply

By CoiiChan·Created about a year ago·Updated about a year ago· 2
Divided
  • imga
  • imgb
  • IMAGE
formularesult = imga / imgb

Division is the blend mode nobody ships, because it's the one that can blow up in your face. result = imga / imgb - per-pixel, per-channel division. Where multiply darkens, divide restores: it's the inverse operation, which makes it the tool for undoing a multiply, normalizing a pass against a reference, or computing ratios between two images (think: dividing an albedo pass by a lighting pass to recover the raw surface color).

Here's the catch that keeps division out of most node packs: dividing by a pixel that's near zero produces enormous values. A dark region in imgb isn't a warning sign, it's a singularity. Feed a shadow-heavy mask into the denominator and your output explodes to hundreds - the tensor is fine holding it, and your preview is not.

How it works

Pre-filled CustomScript-NumPy formula:

result = imga / imgb

NumPy division is elementwise, and it will happily compute x / 0 - you'll get an inf (with a RuntimeWarning: divide by zero in the console) or NaN if it's 0/0. NaNs are the sneaky failure: they render as black/garbage, they propagate through every later op, and they don't error loudly. If your result looks wrong in a "some pixels are just broken" way, suspect NaNs from division.

Inputs and outputs

  • formula - the one-liner, editable.
  • imga - numerator; reference for output resolution.
  • imgb - denominator. This is the dangerous one. Leave it unconnected and it's an all-zero array - congratulations, you've just divided by zero everywhere.

One IMAGE output.

Install

ComfyUI Manager → search "FuncAsTexture", or:

cd ComfyUI/custom_nodes
git clone https://github.com/CoiiChan/ComfyUI-FuncAsTexture-CoiiNode
# restart ComfyUI

No models, no dependencies beyond what ComfyUI ships. Category: FunctionAsTexture.

Making it safe

Division has a well-worn safety idiom: add a small epsilon to the denominator.

result = imga / (imgb + 1e-6)

That's a one-line edit to the formula input, and it tames the singularities while barely changing the real ratios. The pack's philosophy is that these nodes are editable formulas - this is the node where you actually want to use that, because the default formula is exactly as dangerous as it looks. And regardless of epsilon, clamp the output afterward (np.clip(result, 0, 1)) if you're going anywhere near a sampler or preview.

The honest take

You'll use Divided rarely, and you should never use it with an unconnected imgb. But when the problem is "I need to undo this multiply", it's the only tool in the box, and a one-line epsilon tweak makes it safe. Treat it as a sharp tool: useful, and stored with a guard on.

CategoryFunctionAsTexture

Inputs (3)

NameTypeDefaultDescription
formulaSTRINGresult = imga / imgb
imgaoptIMAGEOptional ,Reference size ,Default =(1,512,512,3)
imgboptIMAGEOptional

Outputs (1)

NameTypeDescription
IMAGEIMAGE