Mask_transform_sum
The all-in-one mask preview, crop, and style node
- base_image
- mask
- image
- mask
Most mask nodes do one thing: expand a mask, blur a mask, crop to a mask. Mask_transform_sum tries to be the one node that does all of that at once, plus turn the mask into a visible, composited image so you can actually see what you're working with instead of squinting at a grayscale thumbnail. It's a "sum" node in the pack's own naming - a bundle of the mask utility work you'd otherwise chain five separate nodes to do.
Part of ComfyUI-Apt_Preset's mask toolbox, alongside Mask_splitMask_by_color and Mask_split_mulMask. No models, no downloads - this one's pure image/mask processing, and it's easily the most parameter-dense node in that trio.
How it works
Give it a mask (and optionally a base image) and it does two jobs in sequence. First, it renders the mask as a visible style - mask_mode picks between the raw grayscale mask, a solid filled block, an outline only, a filled or outlined circle approximation, and a couple of block variants. Second, it composites that rendering onto a background chosen by bg_mode - crop to just the mask region, the full base image, a transparent background, or a flat color (white, black, red, green, blue). Between those two steps sit a pile of adjustments: grow or shrink the mask boundary before rendering (mask_expand), feather the edges (smoothness), remap the mask's intensity range (mask_min/mask_max), round the corners on block/outline renders (tapered_corners), and drop tiny stray blobs below a pixel-count floor (ignore_threshold) before any of it happens.
The other job it does, separate from styling, is cropping: turn on crop_to_mask and it'll crop the canvas down to the mask's bounding box, pad that box out with expand_width/expand_height, rescale it (rescale_crop), and snap the final dimensions to a multiple of divisible_by - which matters because most diffusion models choke or degrade on dimensions that aren't a multiple of 8 (or sometimes 16 or 64, depending on the model). That combination - crop to the masked region at a model-safe resolution - is exactly the setup you want before an "only masked" inpaint pass: full generation budget spent on the small area that actually matters, then paste it back.
Inputs and outputs
The two you'll touch first are what actually decide what comes out:
- bg_mode - background choice:
crop_image(crop to the mask),image(full frame),transparent, or a flat color. - mask_mode - how the mask itself is drawn:
original(plain grayscale) is the sane default; the fill/outline/circle variants are for visualizing or stylizing rather than feeding into a sampler.
Past that, the beginner-relevant knobs are crop_to_mask + divisible_by if you're setting up a crop-and-inpaint pass, mask_expand and smoothness if your mask needs to grow a bit and lose its hard edges before it's used, and opacity for how strongly the rendered mask overlays the background image. base_image and mask are both optional inputs - you can preview a mask on its own without a background image if all you want is to check its shape.
Outputs are image and mask. Wire image into a VAE Encode if you cropped down to an inpaint-ready canvas, or just view it directly to sanity-check what your mask actually covers before committing GPU time to a run.
Installing it
ComfyUI Manager: search "ComfyUI-Apt_Preset", install, restart. Or by hand:
cd ComfyUI/custom_nodes
git clone https://github.com/cardenluo/ComfyUI-Apt_Preset.git
Restart after. Windows has install.bat for dependencies in the repo; on Linux/Mac, pip install from the requirements file inside your ComfyUI venv. This node needs no model files - everything it does is local image processing.
Common issues
Output dimensions don't match what you expected after crop_to_mask. That's divisible_by and rescale_crop doing their job - the final size gets rounded to a multiple of divisible_by (default 8) and scaled by rescale_crop, so it won't be a pixel-exact crop of the bounding box unless both are set to leave it alone (rescale_crop at 1, divisible_by at 1). If you need an exact crop, set divisible_by to 1.
A small mask disappears entirely. Check ignore_threshold - anything below that pixel count gets dropped before rendering. It defaults to 0 so this shouldn't bite you unwittingly, but if you or a saved workflow bumped it, a genuinely small mask (a tiny blemish, a distant object) can vanish.
The rendered mask looks washed out or invisible against the background. opacity is probably low, or mask_mode is set to outline/outline_block and the outline is thin relative to the region - bump outline_thickness or switch to a fill mode if you want something you can actually see at a glance rather than a precise but faint boundary line.
Inputs (17)
| Name | Type | Default | Description |
|---|---|---|---|
| bg_mode | COMBO | 8 options: crop_image, image, transparent, white, black, red, +2 | |
| mask_mode | COMBO | original | 7 options: original, fill, fill_block, outline, outline_block, circle, +1 |
| ignore_threshold | INT | 00–10000 | — |
| opacity | FLOAT | 1.000–1 | — |
| outline_thickness | INT | 31–400 | — |
| smoothness | INT | 00–150 | — |
| mask_expand | INT | 0-500–1000 | — |
| tapered_corners | BOOLEAN | true | — |
| mask_min | FLOAT | 0.00-10–1 | — |
| mask_max | FLOAT | 1.000–10 | — |
| crop_to_mask | BOOLEAN | false | — |
| expand_width | INT | 0-500–1000 | — |
| expand_height | INT | 0-500–1000 | — |
| rescale_crop | FLOAT | 1.000.1–10 | — |
| divisible_by | INT | 81–128 | — |
| base_imageopt | IMAGE | — | |
| maskopt | MASK | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |
| mask | MASK | — |