Nodes/comfyui_imgutils/Mask Attributes
ComfyUI Node

Mask Attributes

Brightness, contrast, threshold, and smoothing for masks

By LK-168·Created about a year ago·Updated about a year ago· 1
Mask Attributes
  • mask
  • mask
threshold0.50
smooth_radius0.0
contrast1.0
brightness0.00
invertfalse
binarizefalse

The tone controls for masks

Most mask problems are value problems: the mask is too faint, too harsh, too noisy, or backwards. Mask Attributes is a set of image-editing tone controls applied to a mask - brightness, contrast, smoothing, binarization, inversion - all in one node with sensible defaults of "do nothing." It's the node you wire after a detector or SAM when the mask needs a quick personality adjustment rather than a rebuild.

How it works

A mask is just a grayscale image, so the operations are the standard ones, applied in a fixed order:

  • brightness (−1 to 1) - added to every pixel, clamped to [0,1]. Positive lifts, negative darkens.
  • contrast (0.1 to 3) - scales values around the 0.5 midpoint. Above 1 pushes everything toward pure black or pure white; below 1 flattens.
  • smooth_radius (0–20) - Gaussian blur for feathering. The sigma is radius / 3, so a radius of 3 is a gentle 1-pixel-ish blur and 9 is noticeable.
  • binarize + threshold (default 0.5) - snap every pixel to 0 or 1 at the threshold. On = binary mask, off = soft.
  • invert - flip it: 1−mask.

The two you'll actually use

  • binarize + threshold - the "make this a clean binary mask" move. SAM and detector masks come out with soft gray edges; for a lot of downstream nodes a hard 0/1 mask behaves far more predictably. Set the threshold where the gray fades to background.
  • smooth_radius - the reverse: take a crunchy binary mask and soften it into something an inpaint node blends nicely.

contrast is the middle ground - crank it to 1.5–2.0 to firm up a wishy-washy mask without going fully binary. Output is a single mask socket, same size and batch as the input.

Install

Part of LK-168/comfyui_imgutils. ComfyUI Manager → search "comfyui_imgutils", or:

cd ComfyUI/custom_nodes
git clone https://github.com/LK-168/comfyui_imgutils

Restart ComfyUI. Pure numpy/PIL math - no models, no downloads. (One tiny README detail: the author's own feature list says "binarize" twice in the attribute list. It's a copy-paste wobble, not a hidden feature.)

Common issues

  • Mask vanished / became solid. threshold is set wrong for your mask's value distribution - check the range with Mask Info first, then pick the threshold. A mask with soft 0.2–0.4 values binarized at 0.5 disappears entirely.
  • "Smoothing did nothing." With smooth_radius at 1 the sigma is 0.33 - invisible. Go to 5+.
  • Everything backwards. That's what invert is for; people forget it exists and redo whole pipelines instead of flipping one toggle.

It's a utility node, unglamorous, and it quietly solves the mask-quality problems that make everything downstream worse.

Categoryimgutils/mask

Inputs (7)

NameTypeDefaultDescription
maskMASK
thresholdoptFLOAT0.500–1Threshold for binarization
smooth_radiusoptFLOAT0.00–20Gaussian blur radius for smoothing
contrastoptFLOAT1.00.1–3Adjust mask contrast
brightnessoptFLOAT0.00-1–1Adjust mask brightness
invertoptBOOLEANfalseInvert mask
binarizeoptBOOLEANfalseConvert to binary mask

Outputs (1)

NameTypeDescription
maskMASK