Image math
Pixel math with X, Y and a perlin noise function built in
- V
- F
- Expression
- stack
- IMAGE
- STACK
Image math is where the More Math pack stops being "a nicer arithmetic node" and starts being a small image-processing language. You give it one or more images and an expression, and it evaluates that expression for every pixel - with the pixel's position, the channel, the batch index, even procedural noise, all available as variables. Want a diagonal gradient, a per-channel color shift, or a perlin-noise distortion without loading an extra node pack? This is the tool.
How it works
Every pixel gets evaluated against your expression, and the node hands you variables you can't get from the stock "Math Expression" node because those don't see the tensor at all. For images the pack exposes X and Y (position, top-left origin), W and H (width, height), C for channel, B for batch index, T for batch count, plus the usual per-dimension D0/D1 position and S0/S1 size variables. So a gradient is literally X/W. Channel-aware math is if(C==0, ...) style - the language has real if/else, while, and for control flow, not just ternary tricks.
Beyond that, the expression library is the same one shared across the whole pack: blur, edge, dilate, erode, fft/ifft, perlin(seed, scale, octaves), voronoi, plasma, remap, smoothstep, and full color conversions like rgb_to_hsv and rgb_to_oklab. In practice this node is a whole effects stack in one box.
Inputs and outputs
V is the autogrow list of image inputs (V0, V1, ...), F the float inputs (F0, ...), and Expression is where the magic happens - the default I0*(1-F0)+I1*F0 is a crossfade between two images by a float. There's also length_mismatch (error is default, plus tile and pad) to decide what happens when your inputs have different batch sizes, and a batching integer that controls how many frames are evaluated per pass - leave it at 0 and let the node figure it out, unless you're hitting memory issues.
Output is IMAGE (a list, so it feeds image sequence workflows fine) and STACK. The image goes wherever images go - into a VAE decode, an upscaler, or straight to the preview.
Installing it
Nothing special compared to the rest of the pack:
cd ComfyUI/custom_nodes
git clone https://github.com/mcDandy/more_math
cd more_math
pip install -r requirements.txt
Restart ComfyUI, or find "More math" in ComfyUI Manager. The only real dependency is antlr4-python3-runtime (plus torch, which you have). No models to download.
The gotcha
Per-pixel evaluation means big expressions on big images can get slow - a 1024x1024 image is a million pixel evaluations, so for loops inside the expression multiply that cost. Keep heavy loops out, use the built-in vectorized functions (blur, edge, the noise generators) instead of rolling your own, and watch the batching setting if VRAM complains. This is a brand-new pack with a small user base, so treat it as early-adopter territory: the function list is excellent, but the edge cases (weird channel counts, odd image sizes) are yours to discover.
Inputs (8)
| Name | Type | Default | Description |
|---|---|---|---|
| V | COMFY_AUTOGROW_V3 | — | |
| F | COMFY_AUTOGROW_V3 | — | |
| Expression | STRING,SYNTAX_TREE | V0 | Expression to apply on input images |
| length_mismatch | COMBO | error | How to handle mismatched image batch sizes. tile: repeat shorter inputs; error: raise error on mismatch; pad: treat missing frames as zero. |
| batching | INT | 0 | — |
| remember_stack | BOOLEAN | false | If enabled, stack is copied at output leading to changes being remembered during batch operations (node runs multiple times in sucession). If disabled each batch gets it's own copy of the stack. |
| use_compute_device | BOOLEAN | true | Temporarily copies image tensors to the compute device for math and moves the result back afterwards. |
| stackopt | STACK | Access stack between nodes |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |
| STACK | STACK | — |