Remap Mask Range (YC)
Stretch a dim mask up (or pull a hot mask down) — simple range surgery for masks
- mask
- mask
The author's own description nails it: "Sets new min and max values for the mask." Your mask came out of a segmenter or a preprocessor looking gray and weak - nothing near pure white, nothing near pure black - and you want it to actually behave like a mask. This node rescales the mask's values into a range you pick, which is the polite way of saying it's a brightness-and-contrast knob for masks.
What it's actually for
Masks aren't always binary. A soft mask from CLIPSeg, a depth-derived mask, or a blurred feathered mask has a gradient of gray values, and downstream nodes treat those values as weights. If your mask's brightest pixel is 0.4, that region is only getting 40% strength in the sampler or overlay - no matter how confident you were in the selection. This node fixes that by remapping the mask's values so its top value lands where you tell it to.
How it works
Straightforward linear rescale. It finds the mask's current maximum value, then maps every pixel so that the current max becomes your max setting, with min as the floor:
scaled = mask / current_max × (max − min) + min, then clamped to [0, 1].
Two things to notice. First, it scales off the current max, not the full [0, 1] range - so a mask whose values sit at 0.1–0.4 gets stretched to whatever you ask for, and one that's already full-range keeps its shape while shifting. Second, the result is clamped to 0–1, so asking for min below 0 or max above 1 just pushes values to the extremes - which is the point: drive max up to force pure white where the mask was dim.
Inputs
Three, and only two you'll usually touch:
- mask - in
- min - new floor (−10 to 1, default 0)
- max - new ceiling (0 to 10, default 1)
Default behavior is a no-op for a normal mask, so you're only reaching for this when a mask needs correcting. Output is the remapped mask.
Install
In ComfyUI-YCNodes. ComfyUI Manager → search "ComfyUI-YCNodes" → install, or:
cd ComfyUI/custom_nodes
git clone https://github.com/yichengup/ComfyUI-YCNodes
Restart. Standard deps (torch, numpy, pillow, opencv-python, scipy), no models.
Where people get burned
- Expecting a threshold. This isn't binarization - it won't snap gray values to pure black or white unless you push the ends hard. If you want a hard cut, you want a threshold node, not this.
- Scaling off the max, not the range. A mask whose lowest value is 0.3 stays at 0.3 after remap unless you set
minto push it down. If the whole mask is floating above black, lowermin. - It only stretches upward naturally. A mask that's already full-range white in places won't get "more" contrast - there's nothing above 1 to remap to. This is a fixer, not an amplifier.
For masks that come out of analysis nodes looking washed out, this is a two-knob rescue: raise max to restore punch, or raise min to keep noise out of the bright areas.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| mask | MASK | — | |
| min | FLOAT | 0.00-10–1 | — |
| max | FLOAT | 1.000–10 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| mask | MASK | — |